Support » Fixing WordPress » Archive posts by tag or meta value plus add pagination

  • Resolved luisleguisamo



    Is it possible to archive posts by tag(or meta value) sort them by most recent, and add pagination to this archive?

    This would be the scenario:

    On the main nav we have a link named Sermons.
    We add a Series to the Sermons by using the tag feature or by adding a meta key/meta value.
    For example:
    Tag 1= Fun Series
    Tag 2= Exciting Series
    Tag 3= Motivating Series

    When we click on the Sermons link from the main nav we are then presented with a list of Sermon Series to choose from. These would be sorted by most recent Series post. And ideally, because the Series list would grow, the list would be paginated.

    Is this possible? Please point me in the right direction.

    Thanks in advance!


Viewing 5 replies - 1 through 5 (of 5 total)
  • This certainly should be possible, but might require a fair amount of coding. Email me at mac =at= mcdspot =dot= com to discuss.

    Thanks for replying.

    I figured out a way to use a custom taxonomy for the Series.

    If I want to list all the Series names, the only way I know to do that is by using:

    wp_tag_cloud( array( 'taxonomy'=>'sermonseries' , 'format'=>'list',
    'smallest'  => 12,
    'largest'  => 12) );

    Is there a way to paginate the wp_tag_cloud results?

    Would I need to look into wp_query for a custom query in order to make this work?

    I can’t seem to find many posts on paginating wp_tag_cloud or wp_list_categries results.

    Thanks again!


    You can change the wp_tag_cloud call slightly to return an array:

    $tags = wp_tag_cloud( array( 'taxonomy'=>'sermonseries' , 'format'=>'array',
    'smallest'  => 12,
    'largest'  => 12,
    'echo' => false) );

    Then you can use paginate_links() to paginate the $tags array.

    Sample code for paginate_links:

    // Test the use of paginate_links
    $rows_per_page = 7;
    $current = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
    $rows = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
    global $wp_rewrite;
    $pagination_args = array(
       	'base' => @add_query_arg('paged','%#%'),
       	'format' => '',
       	'total' => ceil(sizeof($rows)/$rows_per_page),
       	'current' => $current,
       	'show_all' => false,
       	'type' => 'plain',
    if( $wp_rewrite->using_permalinks() )
       $pagination_args['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    if( !empty($wp_query->query_vars['s']) )
       $pagination_args['add_args'] = array('s'=>get_query_var('s'));
    echo paginate_links($pagination_args);
    $start = ($current - 1) * $rows_per_page;
    $end = $start + $rows_per_page;
    $end = (sizeof($rows) < $end) ? sizeof($rows) : $end;
    echo '<br />';
    for ($i=$start;$i < $end ;++$i ) {
       $row = $rows[$i];
       echo "I:$i  ID:{$row->ID}  Title:{$row->post_title} <br />";

    Cool thanks!
    I’ll give it shot.

    I ended up creating a custom query like:

    $query = "SELECT * FROM wp_terms,wp_term_taxonomy WHERE wp_terms.term_id=wp_term_taxonomy.term_id AND wp_term_taxonomy.taxonomy='sermonseries'";

    And I used This easy PHP pagination code for the paging.

    However, I will still try to implement your code.

    Thanks again!


    Glad it is working! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Archive posts by tag or meta value plus add pagination’ is closed to new replies.