Support » Fixing WordPress » Custom post type pagination using natural query

  • I’m trying to list my custom posts without a manual query. My custom type is ‘product’ and this is the code I am using to get a ‘page’ that lists my products, based on rewrite slug defined for the post type (something like ‘store’)

    // flush rules to get it working
    function mss_rewrites($wp_rewrite) {
      global $wp_post_types;
      try { $slug = $wp_post_types['product']->rewrite['slug']; }
      catch(Exception $e) { return; }
      $newrules = array(
        $slug.'/?$' => 'index.php?post_type=product',
      $wp_rewrite->rules = $newrules + $wp_rewrite->rules;
    add_filter('generate_rewrite_rules', 'mss_rewrites');

    It works perfectly: shows product X lists all products, respecting the limits, all is ok, but.. shows the first page again
    then I tried, and both URLs are resolved in and shows the first page again.

    Yes, I can do my own query…. but I would like to find a solution in this way.

    Thanks for any help!

  • The topic ‘Custom post type pagination using natural query’ is closed to new replies.