Tell us what you are trying to do?
I am trying to make Custom views persist when paginating
function sorting_modify_orderby( $view_args, $view_settings, $view_id, $default_paged = 1 ) {
global $filtered_post_ids;
if ( 8260 == $view_id ) { // Edit ID
// Ensure filtered_id_by_location is set and is a valid string
if ( isset($_GET['filtered_id_by_location']) && !empty($_GET['filtered_id_by_location']) ) {
// Convert the string of IDs into an array of integers
$ordered_ids = array_map('intval', explode(',', $_GET['filtered_id_by_location']));
// Log the IDs for debugging
error_log('lk-test custom_order_posts: Using filtered IDs: ' . implode(', ', $ordered_ids));
// Only modify the query if $ordered_ids is not empty
if (!empty($ordered_ids)) {
// Modify the view arguments to include only the posts with the specified IDs
$view_args['post__in'] = $ordered_ids;
// Set the orderby parameter to maintain the order of the specified IDs
$view_args['orderby'] = 'post__in';
// Handle pagination if a specific page is requested
if ( isset($_GET['paged']) && is_numeric($_GET['paged']) ) {
$view_args['paged'] = intval($_GET['paged']);
} else {
$view_args['paged'] = $default_paged;
}
} else {
error_log('lk-test custom_order_posts: No valid IDs after filtering');
}
} else {
error_log('lk-test custom_order_posts: filtered_id_by_location GET parameter not set or empty');
}
}
return $view_args;
}
add_filter( 'wpv_filter_query', 'sorting_modify_orderby', 101, 3 );
I have this code here that helps to update view when i run the function , it works fine but it resets the view when i paginate to the second page
This is my html for my pagination
<li class="wpv-pagination-nav-links-item js-wpv-pagination-nav-links-item page-item wpv-page-link-8260-2 js-wpv-page-link-8260-2">
Is there any documentation that you are following?
no
Could you help me with this , i would just like to simply go to page 2 of the views while maintain the views_args