• Hello, first of all thank you for this plugin. Great job. I use this plugin to switch between pages. Is it possible to exclude the pages I have specified from this navigation?
    good work

Viewing 15 replies - 16 through 30 (of 37 total)
  • Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency

    It should work, although I forgot to mention you’ll also need to add another filter for the previous post exclusion which is the same add_filter as above but the first argument is ‘get_previous_post_where’.

    However this should still exclude the pages from the next post function.

    is the website you are working on a local site or publicly accessible so I can give you some code to test?

    Thread Starter petraagency

    (@petraagency)

    Of course, I’m working on a demo site right now, I can test the code you give. Thank you for your interest.

    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency
    I need to see the results of any code I send and I cant if the site is local.

    Please add the following before the return $where in the function I gave you.

    var_dump('hello');

    And the following in your functions file

    function plug_load_options () {
      $transient = get_transient ('wp-post-nav');
      echo 'Transient : ' . $transient;
    
      $defaults = [];
      $options[] = 'wp_post_nav_post_types';
      $options[] = 'wp_post_nav_same_category';
      $options[] = 'wp_post_nav_show_title';
      $options[] = 'wp_post_nav_show_category';
      $options[] = 'wp_post_nav_show_post_excerpt';
      $options[] = 'wp_post_nav_excerpt_length';
      $options[] = 'wp_post_nav_show_featured_image';
      $options[] = 'wp_post_nav_fallback_image';
      $options[] = 'wp_post_nav_out_of_stock';
      $options[] = 'wp_post_nav_switch_nav';
      $options[] = 'wp_post_nav_nav_button_width';
      $options[] = 'wp_post_nav_nav_button_height';
      $options[] = 'wp_post_nav_background_color';
      $options[] = 'wp_post_nav_open_background_color';
      $options[] = 'wp_post_nav_title_color';
      $options[] = 'wp_post_nav_title_size';
      $options[] = 'wp_post_nav_category_color';
      $options[] = 'wp_post_nav_category_size';
      $options[] = 'wp_post_nav_excerpt_color';
      $options[] = 'wp_post_nav_excerpt_size';  
    
      foreach ($options as $option) {
        //check if the option exists in the database
        $option_value = get_option ($option);
        
        //if any exist, create an array for updating them to the new version
        if ($option_value) {
          $defaults[$option] = $option_value; 
        }
      }
    
      echo '<pre> Original Options<br>';
      if ($defaults) {
      print_r ($defaults);
      }
      else {
        echo 'no default options present';
      }
      echo '</pre>';
    
      $options = get_option ('wp_post_nav_options');
      if ($options) {
        foreach ($options as $option => $value) {
          $default_options[$option] = $value;
        }
    
      echo '<pre>New Options<br>';
      print_r ($default_options);
      echo '</pre>';
      }
    }
    add_action('wp_footer','plug_load_options');

    Go to the front end and tell me the following.

    1. Can you see the word hello under the footer of the site (this will confirm the function is added in the right place and is working.
    2. Please tell me the whole of the additional code thats added in the footer

    Thread Starter petraagency

    (@petraagency)

    hi,

    Original Options
    no default options present
    New Options
    Array
    (
        [wp_post_nav_post_types] => Array
            (
                [page] => page
            )
    
        [wp_post_nav_show_title] => Array
            (
                [Yes] => Yes
            )
    
        [wp_post_nav_excerpt_length] => 300
        [wp_post_nav_show_featured_image] => Array
            (
                [Yes] => Yes
            )
    
        [wp_post_nav_fallback_image] => https://xxxx.com.tr/wp-content/uploads/2021/02/favicon.png
        [wp_post_nav_nav_button_width] => 70
        [wp_post_nav_nav_button_height] => 100
        [wp_post_nav_background_color] => #881912
        [wp_post_nav_open_background_color] => #ffffff
        [wp_post_nav_heading_color] => #881912
        [wp_post_nav_heading_size] => 20
        [wp_post_nav_title_color] => #881912
        [wp_post_nav_title_size] => 16
        [wp_post_nav_category_color] => #ffffff
        [wp_post_nav_category_size] => 13
        [wp_post_nav_excerpt_color] => #ffffff
        [wp_post_nav_excerpt_size] => 12
    )
    • This reply was modified 3 years, 8 months ago by petraagency.
    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency hmmm nothing weird there.

    Ok what about the ‘hello’ added via the car dump, does this show?

    Thread Starter petraagency

    (@petraagency)

    Hi,
    It starts with “Transient:” after the footer. There is no record “hello”

    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency

    Then thats the issue. The function to alter the $where clause is not running as you should be able to see the words hello which are dumped to the screen (might not be at the bottom but SHOULD be visible if the function is running)

    Are you using any other plugins to alter the next and previous posts (which theme are you using?)

    Please try deactivating all plugins and see if you can see the words hello on the front end of the screen to confirm the function is running.

    Thread Starter petraagency

    (@petraagency)

    Hi,
    I disabled all plugins but no hello. I’m using flatsome by taking the theme. active plugins classic editor, contact form7, svg support and your plugin.

    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency

    Just to confirm your function in functions php is now as below?

    `
    function wppostnav_exclude_pages($where) {
    global $wpdb;
    var_dump (‘hello’);
    return $where . ” AND p.ID IN (
    SELECT p.ID FROM $wpdb->posts p
    LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id
    WHERE p.ID != ‘742, 744’)”;
    }
    add_filter( ‘get_next_post_where’, ‘wppostnav_exclude_pages’,10,1);
    add_filter( ‘get_previous_post_where’, ‘wppostnav_exclude_pages’,10,1);

    If so, can you change the priority of the function by removing the 10,1 in the addd filter to 999,1 (999 would ensure it runs late and would ensure all other potential filters of the function would run first and then this would run last)

    Thread Starter petraagency

    (@petraagency)

    function wppostnav_exclude_pages($where) {
        global $wpdb;
        return $where . " AND p.ID IN ( 
                          SELECT p.ID FROM $wpdb->posts p 
                          LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id 
                          WHERE p.ID != '742, 744')";
      }
    add_filter ('get_next_post_where', 'wppostnav_exclude_pages', 999,1) ;
    add_filter ('get_previous_post_where', 'wppostnav_exclude_pages', 999,1);
    

    Hi
    I corrected the code like this, but nothing has changed d?m I tried you very hard ??

    Thread Starter petraagency

    (@petraagency)

    I tried with the wp standard theme, not the problem with the theme

    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency your example above isn’t showing the var_dump code which is what we are using to check the function is running.

    Please add this code instead

    function wppostnav_exclude_pages($where) {
        global $wpdb;
        var_dump (‘hello’);
        return $where . " AND p.ID IN ( 
                          SELECT p.ID FROM $wpdb->posts p 
                          LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id 
                          WHERE p.ID != '742, 744')";
      }
    add_filter ('get_next_post_where', 'wppostnav_exclude_pages', 999,1) ;
    add_filter ('get_previous_post_where', 'wppostnav_exclude_pages', 999,1);

    The go to the front end of your site and to a page and check that somewhere on the page the word HELLO is shown.

    This will confirm if the function is running or not

    Thread Starter petraagency

    (@petraagency)

    string(11) "‘hello’" string(11) "‘hello’"
    string(11) "‘hello’" string(11) "‘hello’"

    When I entered the last code you sent, the above code appeared on every page, but the plugin is still not closed on pages with id 742 and 744.

    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency

    So we now know the function is running and working at the right point so its an issue with the filter.

    Please try the following:

    function wppostnav_exclude_pages($where) {
        global $wpdb;
        return $where . " AND p.ID IN ( 
                          SELECT p.ID FROM $wpdb->posts p 
                          LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id 
                          WHERE p.ID NOT IN '742, 744')";
      }
    add_filter ('get_next_post_where', 'wppostnav_exclude_pages', 999,1) ;
    add_filter ('get_previous_post_where', 'wppostnav_exclude_pages', 999,1);

    Ive altered the join from != to NOT IN

    Plugin Author Jo4nny8

    (@jo4nny8)

    @petraagency
    Sorry I noticed an error in the query

    ‘postnav_exclude_pages($where) {
    global $wpdb;
    return $where . ” AND p.ID IN (
    SELECT p.ID FROM $wpdb->posts p
    LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id
    WHERE p.ID NOT IN (‘742, 744’))”;
    }
    add_filter (‘get_next_post_where’, ‘wppostnav_exclude_pages’, 999,1) ;
    add_filter (‘get_previous_post_where’, ‘wppostnav_exclude_pages’, 999,1)’

Viewing 15 replies - 16 through 30 (of 37 total)
  • The topic ‘exclude certain pages when navigating pages’ is closed to new replies.