1

Ok so, I have a page which shows a feed of posts in the "news" category (url is: mydomain.com/category/news ), but the client wants it to also show posts in the "press-releases" category.

So in the category.php page, I used the following code thinking it would loop through all posts which are either in the "news" or "press-release" category:

ob_start();
    single_cat_title();
    $this_cat = ob_get_contents();
ob_end_clean();



if( $this_cat == 'News' || $this_cat == 'Press Releases' ) {

    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'vacation_do_custom_loop' );

}

function vacation_do_custom_loop() {

    global $wp_query;
    global $paged; // current paginated page
    global $query_args; // grab the current wp_query() args


    $args = array(
        'category__in' => '5, 1', // i also tried 'category_name' => 'news, press-releases'
        'posts_per_page' => 9,
        'paged'            => $paged // respect pagination
    );

    genesis_custom_loop( wp_parse_args($query_args, $args) );

}

Well after clicking page 2 (of like 7), Im taken to a 404.

I think the issue is that there is only 1 post in the "news" category, and there are about 40 in "press-releases". So the pagination shows pages for all 40+ posts, but because there is only a single "news" post the second page doesnt actually exist? Since the url is /category/news Wordpress is creating the pagination based on the number of "news" posts?

How can I get pagination working here?

1 Answer 1

0

Provided category names are not changing, and the site is in one language only, you could create two category templates: category-news.php and category-press-releases.php, then everything will pretty much work without you having to fetch the category and including the category__in parameter in the query.

Also, you always want to put your add_action calls inside your 'functions.php`, not inside the template itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.