Forums

Get post data without Template Tags? (2 posts)

  1. cillosis
    Member
    Posted 10 months ago #

    I am working on a plugin and have run into a wall that I can't find the solution for.

    I am trying to gather the posts from the database using $wpdb and the closest I have found is this article in the codex:

    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    The problem lies in the way it uses setup_postdata($post); to populate template tags and then you are supposed to use the tags such as the_title or the_content in order to use the data. When you use one of those template tags, it automatically echos the data to the screen whereas I want to just hold it in a variable for processing.

    How can I get the post data without using template tags?

  2. alchymyth
    The Sweeper
    Posted 10 months ago #

    there are comparable functions - such as get_the_content() or get_the_title() etc; which would return the data.

    http://codex.wordpress.org/Function_Reference/get_the_content
    http://codex.wordpress.org/Function_Reference/get_the_title

    also, there is $post->post_title or $post->post_date etc;
    and apply_filters('the_content', $post->post_content) etc...

    http://codex.wordpress.org/Database_Description#Table:_wp_posts
    http://codex.wordpress.org/Class_Reference/wpdb#Tables

Reply

You must log in to post.

About this Topic