0

I have a few custom post types with custom categories – and i also use the regular posts page for news. At the moment i can only change the number of posts through Settings > Reading > Number of posts – but I would need to have different number of of posts on the CPT category pages. I tried something like this in functions.php:

/* Set limit of category pages to 99 */ function num_posts_archive_project_ie($query) { if (!is_admin() && $query->is_archive('expert_db') && $query->is_main_query()) { $query->set('posts_per_page', 99); } return $query; } 

But to no success…:/ Any pointers or suggestions appreciated. Cheers! t

    1 Answer 1

    1

    You're halfway there. All you're missing is the right hook:

    add_action( 'pre_get_posts', 'num_posts_archive_project_ie' ); 

    The pre_get_posts hook fires after the main WP_Query object is instantiated but before it's sent to the DB.

    1
    • omg yes! thank you very much!!CommentedNov 18, 2024 at 14:30

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.