Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 220691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:57:47+00:00 2026-05-11T18:57:47+00:00

I am writing a WordPress plugin and need to go through a number of

  • 0

I am writing a WordPress plugin and need to go through a number of posts, grab the data from them (for the most part title, permalink, and content), and apply processing to them without displaying them on the page.

What I’ve looked at:

I’ve looked at get_posts() for getting the posts, and then

getting title via the_title(),
content via the_content(),
and permalink via the_permalink()

Keep in mind that I need this data after all filters had already been applied, so that I get the exact data that would be displayed to the user. Each of the functions above seems to apply all necessary filters and do some postprocessing already, which is great.

The Problem:

The problem is all these functions, at least in WP 2.7.1 (latest released version right now) by default just echo everything and don’t even return anything back. the_title() actually supports a flag that says do not print and return instead, like so

the_title(null, null, false)

The other 2, however, don’t have such flags, and such inconsistency is quite shocking to me.

I’ve looked at what each of the_() functions does and tried to pull this code out so that I can call it without displaying the data (this is a hack in my book, as the behavior of the_() functions can change at any time). This worked for permalink but for some reason get_the_content() returns NULL. There has to be a better way anyway, I believe.

So, what is the best way to pull out these values without printing them?

Some sample code

global $post;
$posts = get_posts(array('numberposts' => $limit));

foreach($posts as $post){
    $title = the_title(null, null, false); // the_title() actually supports a "do not print" flag
    $permalink = apply_filters('the_permalink', get_permalink()); // thanks, WP, for being so consistent in your functions - the_permalink() just prints /s
    $content = apply_filters('the_content', get_the_content()); // this doesn't even work - get_the_content() returns NULL for me
    print "<a href='$permalink'>$title</a><br>";
    print htmlentities($content, ENT_COMPAT, "UTF-8"). "<br>";
}

P.S. I’ve also looked at What is the best method for creating your own WordPress loops? and while it deals with an already obvious way to cycle through posts, the solution there just prints this data.

UPDATE: I’ve opened a ticket with WordPress about this. http://core.trac.wordpress.org/ticket/9868

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:57:47+00:00Added an answer on May 11, 2026 at 6:57 pm

    OK, I got it all sorted now. Here is the final outcome, for whoever is interested:

    • Each post’s data can be accessed via iterating through the array returned by get_posts(), but this data will just be whatever is in the database, without passing through any intermediate filters
    • The preferred way is to access data using get_the_ functions and them wrapping them in an call to apply_filters() with the appropriate filter. This way, all intermediate filters will be applied.

    apply_filters('the_permalink', get_permalink())

    • the reason why get_the_content() was returning an empty string is that apparently a special call to setup_postdata($post); needs to be done first. Then get_the_content() returns data properly

    Thanks everyone for suggestions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 106k
  • Answers 106k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer "This could fail if somewhere down the line you end… May 11, 2026 at 8:56 pm
  • Editorial Team
    Editorial Team added an answer Be careful about assuming that int operations are always faster… May 11, 2026 at 8:56 pm
  • Editorial Team
    Editorial Team added an answer Well, I'm mainly a C# guy, but a good formula… May 11, 2026 at 8:56 pm

Related Questions

I am writing a comparison between 3 technology options for building our new website:
I am writing a query in which I have to get the data for
I am writing a few extensions to mimic the map and reduce functions in
I am writing a client-side Swing application (graphical font designer) on Java 5 .
I am writing a webapp using CodeIgniter that requires authentication. I created a model

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.