Page with even post_type wordpress Slug

Asked

Viewed 620 times

2

Buenas

I have a wordpress post_type that calls products.

I created an Archive-products.php and inside it I have the loop. Inside it I need to have, before the list an editable content, and for that have the page called Products, within Pages in wordpress.

What’s the best way to do this without conflicts in the url?

Att,

  • Add the code to the question.

  • I didn’t understand your question very well, you have an already created page called Products or a post_type called Products?

  • Both. Actually post_type calls products. I have an Archive-products.php and I can loop on it normally. However, before the loop need a dynamic content, which would have to be within pages in the wordpress menu. If I create a products page, to wordpress get the global $post automatically, the url will conflict, the page with the post_type. I have already created a page with a different url than post_type and I loop taking this page inside the Archive-products. That way it works, but I don’t even know if it’s the best way to do it. :)

2 answers

1

You have to choose which page you want to get your website.com/products URL.

If it’s the page you’re creating inside the panel, you’ll need to change the post_type permalink. If you are registering this post_type programmatically you should add the rewrite argument, as per Codex:

rewrite (Boolean or array) (optional) Triggers the Handling of rewrites for this post type. To Prevent rewrites, set to false. Default: true and use $post_type as Slug $args array 'Slug' => string Customize the permalink Structure Slug. Defaults to the $post_type value. Should be translatable. 'with_front' => bool Should the permalink Structure be prepended with the front base. (example: if your permalink Structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true 'feeds' => bool Should a feed permalink Structure be built for this post type. Defaults to has_archive value. 'pages' => bool Should the permalink Structure provide for pagination. Defaults to true 'ep_mask' => const As of 3.4 Assign an endpoint Mask for this post type. For more info see Rewrite API/add_rewrite_endpoint, Trac Ticket 19275, and this Make Wordpress Plugins Summary of endpoints. If not specified and permalink_epmask is set, Inherits from permalink_epmask If not specified and permalink_epmask is not set, defaults to EP_PERMALINK

I also recommend using a different file for this page, instead of Archive-produtos.php. The best is to use a page-products.php template and leave Archive-products.php for a simple post type products file. So you don’t run the risk of the page being called by the post type url and the contents of the first loop not being found.

If you want the custom post type products page to have this url, then just change the title of the page you are creating inside the Panel and remember to use a template for this page. About templates

  • Thank you very much, guys. Really the way is to make templates and/or pages and call the loop inside the template. Archive, use only when it is simple and do not need the page itself to have a dynamic content. Thanks again for the idea of you.

0

Good morning, I had a similar problem once. The page and the Custom Post Type had the same Lug and to solve I always used singular name for Custom Post Type, in your case it would be product instead of products.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.