0

I have excluded the first 5 posts from the first page on the main page This is the only code that works for me in my functions.php:

function my_function_for_excluding_posts( $query ) {
if ($query->is_home() && $query->is_main_query()) {
    $offset = 5;
    $paged = 0 == $query->get( 'paged' ) ? 1 : $query->get( 'paged' );
    $query->set( 'offset', $paged * $offset );
    function myprefix_adjust_offset_pagination($found_posts, $query) {
if ( $query->is_home() && $query->is_main_query() ) {
    return $found_posts -5;
}
return $found_posts;

}
    }
}
add_action( 'pre_get_posts', 'my_function_for_excluding_posts' );

add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );

But the admin panel error shows an error. How can I fix it?

Admin panel all posts

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'myprefix_adjust_offset_pagination' not found or invalid function name in D:\EasyPHP-DevServer-14.1VC9\data\localweb\wp-includes\class-wp-hook.php on line 298

Thank you for your help

0

I could be wrong here, but you're calling a function "myprefix_adjust_offset_pagination" with the add_filter option, but you're not actually making that function unless it's on the homepage as that function is created behind the if is_home statement. This would explain why you get the error on your admin page. Try pulling that function out, or not that part of the code as a function.

  • thankyou sir, But I do not understand much What kind of code should I create can you help me please – blurain82 Mar 2 '17 at 7:07
  • remove thiss code: add_action( 'pre_get_posts', 'my_function_for_excluding_posts' ); but error: Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'myprefix_adjust_offset_pagination' not found or invalid function name in D:\EasyPHP-DevServer-14.1VC9\data\localweb\wp-includes\class-wp-hook.php on line 298 – blurain82 Mar 2 '17 at 7:15
  • remove this code: add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 ); extra last page on the paginations, and 404 error – blurain82 Mar 2 '17 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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