[Resolved] Option to change number of posts per page when using archive
This thread is resolved. Here is a description of the problem and solution.
Problem:
Option to change number of posts per page when using archive
Solution:
The 'wpv_filter_query' hook will work for views not for archives. If you want to filter archive query arguments on fly either you will have to use pre_get_posts hook or the 'wpv_action_apply_archive_query_settings' hook.'
It says to replace "1234" with the actual ID of the view. This works fine on views that I created, but not on the Posts archive page.
In Toolset > WordPress Archives, the ID is 111, but when I hover over the link I see an ID of 112. I tried both IDs in the function but still it does not work.
I then tried modifying the function to this but it still doesn't work (with or without the is_archive() :
// Allow the Archive Custom Search to choose how many posts to display
add_filter( 'wpv_filter_query', 'filter_items_per_page_custom_fn', 1000 , 3 );
function filter_items_per_page_custom_fn( $query_args ) {
Hello. Thank you for contacting the Toolset support.
The 'wpv_filter_query' hook will work for views not for archives. If you want to filter archive query arguments on fly either you will have to use pre_get_posts hook or the 'wpv_action_apply_archive_query_settings' hook.
Can you please try to use the following code and check if that help you to resolve your issue:
function modify_query($query, $archive_settings, $archive_id){
if($archive_id==111) { //change this to the view ID of your archive page
if(empty($_GET['item-per-page'])) {
$query->set('posts_per_page', 6);
} else {
$query->set('posts_per_page', $_GET['item-per-page']);
}
}
}
add_action('wpv_action_apply_archive_query_settings','modify_query',31,3);