We're merging with GenerateBlocks! Learn more here.

[Resolved] Possible to show posts by taxonomy, rather than by specific terms?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Possible to show posts by taxonomy, rather than by specific terms?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #3854
    Adrian
    Participant

    I need a way to show posts that belong to the same custom taxonomy terms as the current post.

    For example, if the current taxonomy of a post contains the term “Convertible Cars”, can I show all other posts that also share that same term, without having to create a unique WP Show Post ID for Categories > Convertible Cars which I’ll then have to copy manually into each and every post about convertible cars?

    I tried this but it’s not working, perhaps because I need it to look for terms within 1 of 4 custom taxonomies I’m using.

    <?php
    $term_slug = get_queried_object()->slug;
    
    wpsp_display( 1508, 'tax_term="' . $term_slug . '"' );
    ?>

    (1508 is the ID of my post list)

    Maybe this code needs to be modified to define the custom taxonomy name I’m using for this?

    #3886
    Adrian
    Participant

    Any luck with this?

    #3903
    Tom
    Keymaster

    Hmm, can you test something for me?

    After this: $term_slug = get_queried_object()->slug;

    Add this: var_dump($term_slug);

    Is the value correct?

    #3918
    Adrian
    Participant

    It shows string(0) ""

    #3922
    Tom
    Keymaster

    K, that’s the issue.

    Let’s try this instead:

    $terms = get_the_terms( get_the_ID(), 'your-taxonomy' );
    
    if ( !empty( $terms ) ){
        // get the first term
        $term = array_shift( $terms );
        $term_slug = $term->slug;
    }
    
    wpsp_display( 1508, 'tax_term="' . $term_slug . '"' );
    #3925
    Adrian
    Participant

    Getting closer 🙂

    Now it just says that no posts were found.

    How can I point this to my custom taxonomy called Similars? I tried this, but no luck:

    $term_slug = get_query_var( 'similar' );
     wpsp_display( 1508, 'tax_term="' . $term_slug . '"' );

    I tried ‘similar’, ‘Similar’ and ‘Similars’.

    #3929
    Tom
    Keymaster
    #3931
    Adrian
    Participant

    Works perfectly now, thanks so much Tom!!

    #3940
    Tom
    Keymaster

    You’re welcome! 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.