WordPress.org

Support

Support » How-To and Troubleshooting » Custom post type list without a custom loop

Custom post type list without a custom loop

  • Hi
    I’m working with a post type ‘product’, created in this way:

    $args = array(
        [...]
        'rewrite' => array('slug' => 'store', 'with_front' => false),
        [...]
      );

    in my local system I get the products list accessing http://mysite.com/store/ without any extra code, the products list happens naturally… but when I try it online, I get a 404 error (page not found).

    Searching this forum, I see several items showing custom loops to display custom posts. Is it necessary? So, why it works in my local server?

    The rewrite rules are the same in both installations (after flushing), but $wp_query shows that in local machine $wp_query->query_vars['post_type'] = 'product' while in online version, $wp_query points to a unknown ‘page’ – with exactly the same
    rewrite rules!!!

    PS. there is not a page or post with the slug ‘store’ .

    Any help would be appreciated

Viewing 9 replies - 1 through 9 (of 9 total)
  • Could you please post the whole register_post_type function call?

    esmi

    @esmi

    Forum Moderator

    If the function is more than 10 lines long, please use the pastebin.

    Ok, here is the function that includes the post type: http://wordpress.pastebin.com/C0LCzdMz

    Sorry, after paste I see that the code was with
    ‘rewrite’ => array(‘slug’ => ‘loja’, …

    Just to say that this is not an error, ok? ‘loja’ is store in portuguese and I translate just for ask for your help.
    🙂

    Try visiting the Permalink Settings page (online version) and save it (no need to actually change anything and ignore any messages related to modifying the .htaccess file) to recreate rules.

    already did that… with no changes

    Custom post archives aren’t created automatically (but coding them isn’t difficult). So it seems the real question is “So, why it works in my local server?”

    It’s worth noting that the upcoming 3.1 version will support custom post type archives.

    Thank you, molnarm. The hope is dead, but now I kown what to do!

    I know there are many topica here about it, but I solved the problem with this simple function:

    // adapted from Simple Custom Post Type Archives
    function mss_rewrite_rules($wp_rewrite) {
      $post_type = get_post_type_object('product');
      $type_slug = $post_type->rewrite['slug'];
      $new_rules = array(
        $type_slug.'/?$' => 'index.php?post_type=product',
        $type_slug.'/page/?([0-9]{1,})/?$' => 'index.php?post_type=product&paged='.$wp_rewrite->preg_index(1),
        $type_slug.'/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=product&feed='.$wp_rewrite->preg_index(1),
        $type_slug.'/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=product&feed='.$wp_rewrite->preg_index(1)
      );
      $wp_rewrite->rules = array_merge($new_rules, $wp_rewrite->rules);
    }
    add_action('generate_rewrite_rules', 'mss_rewrite_rules' );

    But why it works in my local server (without this function) is still a mistery.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom post type list without a custom loop’ is closed to new replies.