How to show all posts for specific taxonomy?
- This topic has 26 replies, 2 voices, and was last updated 4 years, 7 months ago by
EddyPiV.
-
AuthorPosts
-
August 28, 2020 at 11:02 PM #21511
EddyPiV
ParticipantHi,
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/RBuOZn7LBecause 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?
August 29, 2020 at 9:12 AM #21517Long Nguyen
ModeratorHi 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.
August 29, 2020 at 6:06 PM #21524EddyPiV
ParticipantI understand what you are saying on selecting the taxonomy archive, makes sense to me.
So I changed it accordingly. https://share.getcloudapp.com/geuzOjGLBut 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.
August 30, 2020 at 3:02 PM #21538Long Nguyen
ModeratorHi 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.
August 30, 2020 at 7:23 PM #21541EddyPiV
ParticipantHi 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?
August 31, 2020 at 8:43 AM #21544Long Nguyen
ModeratorHi,
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.
September 1, 2020 at 5:02 PM #21583EddyPiV
ParticipantHi 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?
September 1, 2020 at 10:46 PM #21588Long Nguyen
ModeratorHi,
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/.
September 2, 2020 at 4:27 PM #21595EddyPiV
ParticipantI 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/nOukLv58Why am I not seeing the 2 posts that are there that meet the criteria in the location?
September 3, 2020 at 10:43 AM #21609Long Nguyen
ModeratorHi,
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.
September 3, 2020 at 7:39 PM #21625EddyPiV
ParticipantOkay, 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/YEuozDmvSeptember 3, 2020 at 10:46 PM #21633Long Nguyen
ModeratorHi,
With the custom query, we have to use the variable of the post object. Example:
- Title: post.post_title
- Excerpt: post.post_excerpt
- Thumbnail: get the post thumbnail by post ID https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/.
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 oflocation
, see more in this documentation https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters.September 7, 2020 at 5:59 PM #21691EddyPiV
ParticipantHi,
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...
September 7, 2020 at 6:21 PM #21692EddyPiV
ParticipantActually, 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...September 7, 2020 at 10:35 PM #21693Long Nguyen
ModeratorHi,
Could you please switch to the default theme of WordPress (Twenty Twenty) then check the archive page again?
-
AuthorPosts
- You must be logged in to reply to this topic.