WordPress.org

Ready to get started?Download WordPress

Forums

Number of posts returned by query (3 posts)

  1. DataGnostics
    Member
    Posted 4 years ago #

    I'm doing a filtered query:

    add_filter('posts_where', 'filter_where');
    	query_posts ($query_string . '&cat=457');

    filter_where is a time filter. As you can see, I'm pulling posts from a certain category during a certain timeframe.

    What I want is to know at this point whether any posts fit the query, whether it returned any hits. If it did, the posts will go in one place (in a magazine-like format); if it didn't, they go to another. I figured that I'd be able to do a simple "if N >0 do this, if N=0 do that" -- but I can't figure out what function to use to get N.

    Thanks in advance.

  2. vtxyzzy
    Member
    Posted 4 years ago #

    Try this:

    $number_of_posts = (have_posts()) ? sizeof($wp_query->posts) : 0;

  3. jasonistaken
    Member
    Posted 3 years ago #

    Or you could just use:

    $wp_query->post_count

Topic Closed

This topic has been closed to new replies.

About this Topic