Support Forum
Support › MB Custom Post Type › Permalink for CPT Archive of specific categoryResolved
On a regular post, we've got the /blog/category/category-slug/ structure. Is it possible to have the same structure for a custom post type?
I've got a CPT, that has the Category taxonomy registered (default WP) and has got Archives enabled. The individual post and the archive page works without any issue. What I'd like to have as well is an "archive" page that will only show the CPT entries that have got a specific category assigned.
What would be the best way to do that? Thanks a lot!
Hi Jorge,
You can create a custom taxonomy and assign it to the CPT, no need to use the Category default of WordPress which is assigned to the Post.
Then use this plugin to create a custom permalink for the custom taxonomy https://wordpress.org/plugins/custom-post-type-permalinks/
Thanks Long,
Is there any "actual" difference/advantage on having a custom Taxonomy over the default WP one?
I'll toy around with the CPT permalink plugin, thanks for the link!
I've installed the plugin and did a custom taxonomy, so the archive for the category is working!
However, tinkering with the view for it, if I select to render for the whole page layout or the layout between header and footer, it works just fine, and loads the layout without any issue.
But if I select to render only in the post content area with any of the three options it doesn't work.
The page displays the regular loop and it shows the metabox' view sanitized, no tags, classes, links, anything. Just plain text repeated after every item on the loop.
I'm not sure what could I be doing wrong here. :/
Hi Jorge,
If you set the view render for the post content area in the Archive page, the view content will replace each post content in the list posts. Please refer to this topic https://support.metabox.io/topic/tag-archive-my-view-gets-ignored-when-rendering-only-the-post-content-area/
Hi Long, thank you the video explains way better the situation, it's exactly that. I understand that it is in fact working. So let me rephrase/clarify my question:
Is it possible to generate a metabox view that is used on a dynamic generated page (an archive page) to be displayed at only the post content area, replacing the post content?
In the mean time, I'm trying the shortcode route (which would render the archive page "useless", which is not necessarily a bad thing), using this thread as reference.
So, I set up the code like this, just to see if it works:
<div class="doc-container">
{% set args = {post_type: 'documento', posts_per_page: -1} %}
{% set posts = mb.get_posts( args ) %}
{% for post in posts %}
<p>{{ post.title }}</p>
{% endfor %}
</div>
The post is configured to be requested via query var, to be shown in REST, to be publicly queryable, it is not excluded from search and it's public.
Placed the shortcode on a regular page. And the shortcode does create the div.doc-container
and creates 2 empty p tags (which is expected, since there are only 2 posts published. Am I missing something here?
Hi,
As on this post, you can access the properties of the post object when using a custom query.
<p>{{ post.post_title }}</p>
Sorry for the late reply, as you can see on my previous post, I've got exactly the same structure however this <p>{{ post.post_title }}</p>
returns empty. As well if I add the custom field (which is a File Advanced type). The shortcode, displays the whole html layout, but not the content from the query.
<div class="doc-container">
{% set args = {post_type: 'documento', posts_per_page: -1} %}
{% set posts = mb.get_posts( args ) %}
{% for post in posts %}
<p>This - {{ post.title }}</p>
{% for item in post.descarga_archivo %}
<a href="{{ item.url }}">{{ item.title }}</a>
{% endfor %}
{% endfor %}
</div>
So I'm not sure if I need to do the query on a different way, or if it's something wrong with the one I'm making.
Hi Jorge,
Please follow this documentation to know how to use the Custom Query https://docs.metabox.io/extensions/mb-views/#custom-query
Let me know how it goes.
Thanks Long, that solves the "Title" part, which now looks like this: <p>{{ post.post_title }}</p>
and works great.
I've got a File Advanced field on the post. On the documentation I couldn't find any reference on how to call those. I'm inserting it using the "Insert Field" button without any other change. Which I think it's not part of the post object, from what I understand is that I'd need to use the rwmb_meta()
helper, but I am not sure on how to use it there (and how to call the File Advanced in there). Is there any example I could use to get this going properly? (I'm starting to feel a bit over my head with the custom fields thing).
Thanks!
Hi Jorge,
Follow the documentation of the File Advanced field to know how to show file information https://docs.metabox.io/fields/file-advanced/#template-usage
You need to create a for loop to show the file info, here is the sample code
{% for post in posts %}
{% set files = mb.rwmb_meta( 'descarga_archivo', '', post.ID ) %}
{% for item in files %}
<a href="{{ item.url }}">{{ item.name }}</a>
{% endfor %}
{% endfor %}
Got that Long! Thanks a lot, it was quite easy to set that up knowing where to look. Thanks for the example.
I've set it up to show on the Archive Page of a specific custom taxonomy archive, and it does show the view properly (replacing the content between the header and footer as you pointed earlier), but it doesn't filter out the posts it shows all of them no matter if it matches the custom taxonomy or not. It doesn't really surprise me, since there's no actual reference/filter to it on the view itself, other than the display one.
If I were using the "regular" WP categories, I'd add to the arguments the category->ID and would be done, ending up like this: {% set args = {post_type: 'documento', category: 39, posts_per_page: -1} %}
But I'm not sure how do I add the custom taxonomy from Metabox to it? (I think the answer is right on my nose, but still not finding it).
Thank you for your help, I'm understanding quite better how to seam together all the metabox' parts!
Hi,
Please refer to this topic to know how to query posts by custom taxonomy https://support.metabox.io/topic/display-recent-post-from-the-terms/