Skip Navigation

[Resolved] Display related posts on a taxonomy term archive

This thread is resolved. Here is a description of the problem and solution.

Problem: I use a custom taxonomy "Directors" applied to a CPT "Movies". I also have a custom post type "Directors". I would like to be able to show all the movies by each Director in my Directors taxonomy archive, as well as information from the Director CPT. I would also like to be able to show all the Movies by the current Director in the Director CPT single post.

Solution:
- Create Director CPT posts and Director taxonomy terms such that each Director CPT has a corresponding Director Term. The slugs should always match.
- Associate the Director term with all Movies by that Director.
- On the Director taxonomy archive, insert a View of Movies filtered by Director taxonomy term, set by a shortcode attribute. The term slug can be determined using the wpv-taxonomy-archive shortcode.
- On the Director post Layout, insert a View of Movies filtered by the Director taxonomy, set by a shortcode attribute.
- Fill in the value of the shortcode attribute with the current Director post's ID by using a custom shortcode to convert the current Director's post slug into its post ID. The slug of the current Director post will match the slug of the same Director taxonomy term, so the View of Movies will show the correct results.

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 22 replies, has 2 voices.

Last updated by ritaV 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#611936
after add shortcode in toolset setting.png

So now the shortcode run, you can see my screenshot but...
now how do we cook to see my cpt directors in my taxonomy directors?

#611948

Great! It looks like the View is working now, because you can see the Director CPT title just after "View: ". It matches the taxonomy archive - AHN BYEONG KI. You can delete all the extra debug information we added in the View to test the archive slug and custom shortcodes.

To show other information about the Director CPT here, add that information to the View. In the Loop Output editor, insert any custom fields or other shortcodes you want to display. For example:

<wpv-loop>
[wpv-post-link] - a link to the Director CPT
[wpv-post-featured-image] - the Director CPT featured image
[wpv-post-excerpt] - the Director CPT post excerpt
[types field='some-custom-field-slug'][/types] - a custom field in the Director CPT post
</wpv-loop>
#612006
cpt.png
taxonomy.png

Great! Wow! Fantastic! Now all run fantastic!

See me screenshoot.
I had to create a link to refer to the cpt director because with views I can not create beautiful layouts like layouts.
Confirm this is the best system? Otherwise there is a lot of CSS also for responsiveness.

One last curiosity.
Can I do the same for my actors?
or the function and the shortcode that I have inserted in functions.php and in the settings of toolset is unique and can be valid only for one cpt at a time?

#612010

Hello! Always me ... I noticed an error but I do not know if it is solvable.

If I click on the taxonomy of a director that I have not yet created as a cpt I see the whole list of directors that I added instead of an empty box. And after all the directors I added as cpt I see the wordpress archive associated with that taxonomy.
Is there a way to show an empty box if a cpt is not associated with the same slug?

Error: Attachment size exceeds the allowable limit of 1MB so see my link:
hidden link

#612015

I had to create a link to refer to the cpt director because with views I can not create beautiful layouts like layouts.
Confirm this is the best system?

There is not a way to include a Layout inside a View, so if you prefer the Layouts design I think linking to the Director CPT is fine. Otherwise, you must work with HTML and CSS to make the View look just like the Layout.

Can I do the same for my actors?
Sure, the same technique will work for Actors CPT and Actors Taxonomy Term. The shortcode we created to get a term ID by slug will work for any CPT or Taxonomy, as long as the taxonomy term slug matches the post slug. You must update the post type slug and taxonomy slug here:

[get_id_by_slug_and_type slug='actor-post-slug' type='actor-type-slug']

Is there a way to show an empty box if a cpt is not associated with the same slug?
Yes, update the code in functions.php:

function get_id_by_slug_and_type_func($atts) {
  $page_slug = $atts['slug'];
  $post_type = $atts['type'];
  $page = get_page_by_path($page_slug, OBJECT, $post_type);
  if ($page) {
    return $page->ID;
  } else {
    return 0;
  }
}
add_shortcode('get_id_by_slug_and_type', 'get_id_by_slug_and_type_func');

Then you can modify the "No items found" message in the View.

#612021

WOW!
Fantastic and great!

I solved everything! and I'm really happy, even my client can be satisfied.
You have been an angel and I thank you from the bottom of my heart.
Thanks thanks thanks.
Fast, professional and clear step by step.
If I build a good project it will also be thanks to you and the whole toolset team.

I can close this ticket but I'm afraid of losing you!

#612028

I'll be here when you have another ticket 🙂 Good luck with this project.

#612032

THANK YOU SO MUCH CHRISTIAN!