Much ado about paged tag results (4 posts)

  1. scheurbert
    Posted 8 years ago #

    Could anyone please tell me if there is a built-in method to return paged results for a particular tag, or a possible workaround for this? Apologies that my SQL and WP knowledge aren't extensive enough to figure this out myself. I've created a tag.php template file to display the results of related posts listed within a tag but it only displays the maximum number of posts correlating to the Blog Pages option value (which is technically what it should do).

    Do $paged and query_posts() only work with paginated Pages and not with dynamically generated results?

  2. hakre
    Posted 8 years ago #

    Well "asking the question is knowing the answer" ;):

    query_posts( sprintf('tag=%s&paged=%d', $tag, $paged) );

    Undocumented query_posts tag parameter so far as I am aware of:

    1. tag (string)
    2. tag_id (int)
    3. tag__in (array)
    4. tag__not_in (array)
    5. tag__and (array)
    6. tag_slug__in (array)
    7. tag_slug__and (array)

    see wp-includes/query.php function parse_query();

  3. scheurbert
    Posted 8 years ago #

    Awesome, thanks for that! I should really learn more about that query_posts function as I think it could possibly clean up my existing messy SQL queries. I wonder if it's possible to filter a post based on a particular meta value and order by the post date; I will do some research!

  4. hakre
    Posted 8 years ago #

    Well, mostly that query function does all what is needed for standard wordpress operations. Sometime you should use an own query instead because you can better optimize them. But as long as this is about standard operations (like displaying tagged posts) I would prefer to use the build in standard.

Topic Closed

This topic has been closed to new replies.

About this Topic