Support Forum
Hi,
I am trying to show all posts for a specific taxonomy, but I am getting only the current page.
This is what I did:
My template settings: https://share.getcloudapp.com/bLuR5K6X
My settings: https://share.getcloudapp.com/RBuOZn7L
Because I want similar archive views for each value of the taxonomy, I have created a page per taxonomy, with the shortcode of the view in it.
But the result is that I only see that page containing the shortcode with the view, actually: my current page.
What is it that I am doing wrong?
Hi Eddy,
If you want to apply a view for all term archives of a taxonomy, please set the location Taxonomy Archive - All. See my screenshot https://share.getcloudapp.com/Kour1pv8.
Then you can edit the term to get the link of the archive page https://share.getcloudapp.com/qGuNxQAP.
I understand what you are saying on selecting the taxonomy archive, makes sense to me.
So I changed it accordingly. https://share.getcloudapp.com/geuzOjGL
But the result is the same: I only see 1 item listed: my current page, not any posts!
Because I will have a seperate archive view for each value of the taxonomy, I think I need for each value a separate page with the shortcode of the view.
Is that correct?
So that's what I did, but it's not working.
Hi Eddy,
If you select the location Taxonomy Archive, just go to CPT > Taxonomy > Edit a term > View taxonomy, to get the link of the archive page. For example, the WooCommerce Product category https://share.getcloudapp.com/jkuZOJdY.
Hi Long,
The point is that the taxonomy is assigned to various posttypes: posts, media, pages, cpt's.
With your approach, I get them all, but I only want the posts.
How to do that?
Hi,
Each post type has its own taxonomy and it is separated in the Location. See my screen record for more information https://www.loom.com/share/6368ef09af6d4072a9ba2251637ba181.
Hi Long,
I understand that the different values of the taxonomy each have their own slug.
But what - in your example - if the block category is assigned to post, pages and cpt x, and I only want to see the items with category block for the cpt x?
Hi,
You can check the post type by the post ID. Here is the sample code in View.
{% for post in query.posts %}
{% if(mb.get_post_type(post.ID) == 'post_type_slug') %}
{{ post.title }} - {{ post.url }}
{% endif %}
<br>
{% endfor %}
For more information, please follow this documentation https://developer.wordpress.org/reference/functions/get_post_type/.
I just get an empty screen.
This is the view: https://share.getcloudapp.com/Apukg9Y9
This is the location: https://share.getcloudapp.com/DOuxKBqA
This is the page: https://share.getcloudapp.com/z8uZbrr5
These are the posts: https://share.getcloudapp.com/z8uZbrZQ
This is the result: https://share.getcloudapp.com/nOukLv58
Why am I not seeing the 2 posts that are there that meet the criteria in the location?
Hi,
Understand the problem, you are using the shortcode to display the view on a page but the view has set to the location archive. Use the location archive that means it only shows on the archive page as I mentioned above.
go to CPT > Taxonomy > Edit a term > View taxonomy, to get the link of the archive page. For example, the WooCommerce Product category https://share.getcloudapp.com/jkuZOJdY
You can also follow this documentation to know about the archive page https://developer.wordpress.org/themes/basics/template-hierarchy/.
If you want to create a page that shows the post with specific taxonomy, please choose the location custom, then use the custom query with the function get_posts() to show posts. Here is the sample code:
{% set args = { post_type: 'post', posts_per_page: 5, tax_query: [ { taxonomy: 'category', field: 'slug', terms: 'block' } ] } %}
{% set posts = mb.get_posts( args ) %}
{% for post in posts %}
{{ post.post_title }}
{% endfor %}
See my screenshot https://share.getcloudapp.com/rRu7m0p5.
Okay, that clarifies that part.
Then I proceed with the Custom view, and I will include the shortcode.
I have adapted the view according to your advise, but it seems it finds no records: I get 5 items, each without title, excerpt etc, but all with the current date & time.
https://share.getcloudapp.com/YEuozDmv
Hi,
With the custom query, we have to use the variable of the post object. Example:
See more in this documentation https://developer.wordpress.org/reference/classes/wp_post/.
In the code set args, the field should be slug
(term slug is rotterdam) instead of location
, see more in this documentation https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters.
Hi,
I am confused, I still couldn't figure out how to get all posts for a specific value of a taxonomy.
It looks like my view is ignored at all.
This is the view: https://share.getcloudapp.com/12uJlQwX
This is the location: https://share.getcloudapp.com/Z4ukNpQ8,
This is the value for the taxonomy: https://share.getcloudapp.com/RBuOAkKL
This is the result: https://share.getcloudapp.com/nOuk7JBw
It shows just all posts, pages and cpt's for this value of the taxonomy. Also, the initial text "This is the archive view" does not appear.
Your help is much appreciated...
Actually, I believe I don't understand how the location works in relation to the url of the acrchive page.
Just a simple location is okay, but once it gets more (AND / OR relations) I am lost.
Although in the case above, even with a single condition it already seems ignored...
So if you please could elaborate...
Hi,
Could you please switch to the default theme of WordPress (Twenty Twenty) then check the archive page again?