Thursday, August 18, 2022
HomeWordPress Developmentwp question - Get X posts with the identical phrases as the...

wp question – Get X posts with the identical phrases as the present submit (customized submit kind and customized taxonomy)


I need to present an inventory of posts with the identical phrases because the submit you’re at the moment viewing (it is principally a associated posts record).

It is a customized submit kind (known as “oferta”) and a customized taxonomy (“categoría”).

I need to present 5 posts most (not all) as an ul record.

I am utilizing many of the code from https://wordpress.org/assist/matter/query-cpt-that-share-the-same-taxonomy-as-the-current-cpt/

                $custom_terms = wp_get_post_terms( get_the_ID(), 'categoria');
                $args = array(
                  'post_type' => 'oferta',
                  'tax_query' => array(             
                       array(
                          'taxonomy' => 'categoria',
                          'posts_per_page' => 5,
                          'discipline' => 'slug',
                          'phrases' => $custom_terms[0]->slug, 
                      ),
                   )
                );

                $loop = new WP_Query( $args );
                echo '<ul>';
                whereas ( $loop->have_posts() ) : $loop->the_post();
                    echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a><li>';
                endwhile;
                echo '</ul>';

                wp_reset_postdata();

I’ve managed to get the record, but it surely has 3 issues:

  • It is not limiting to five posts
  • It is duplicating the li components (1
    right component, 1 empty component)
  • It is exhibiting the present submit additionally
    on the record (I solely need to present the opposite posts with the identical time period,
    not the present submit)

For instance, I get this on one of many posts:

enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments