• Hi all,

    Currently I am working on a certain CPT, which lists other cpt’s when related by a certain id. But I would love to only show this when there is at least 1 other cpt with thesame ID. Also, I’d like to remove the current cpt from the list. Who can help me out here?

    This is what I could find so far:

    <?php 
    $args = array( 
    'orderby' => 'title',
    'post_type' => 'cats',
    'meta_key'		=> 'uniquekey',
    'meta_value'	=> $uniquekey
    );
    $the_query = new WP_Query( $args );
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Read about exclude and meta query arguments:
    https://developer.www.ads-software.com/reference/classes/wp_query/

    Thread Starter Klaas Koopman

    (@inspired-media)

    Hi Joy,

    Thank you for your quick reply. I have looked through that page multiple times, but never found anything about excluding based on a custom post type field. I’m no php programmer, perhaps that’s why I’m missing it? Would love to see your reply!

    And thanks in advance for your time and effort, I really appreciate it.

    This argument lets you exclude the post you are currently looking at
    post__not_in (array) – use post ids. Specify post NOT to retrieve.
    You didn’t show much code or even explain your setup, so all I can say is to add
    'post__not_in' => array ( $current_id ),
    to your arguments (of course, setting that variable before using it)

    You can use $the_query->have_posts() to check if there are any results.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CPT Loop Query; Showing when minimum of 2 and without current?’ is closed to new replies.