1

I am trying to include a meta_query to only show the 'post_type' => 'want-to-sell-post' that have the key 'key' => '_wpcf_belongs_artist_id',.

Right now, all want-to-sell-posts are being displayed, and the meta_query is being ignored. What's the error in the way I'm writing this?

Thanks so much!

<?php
    $artist_id = get_the_ID();

    $want_to_sell = new WP_Query( array(
    'post_type' => 'want-to-sell-post',
    'posts_per_page' => 5,
    'meta_query' => array(
        'key'     => '_wpcf_belongs_artist_id',
        'value'   => $artist_id,
        'compare' => '=',
    ), 
));  
?>
<div class="container">
    <div class="row row-cols-1 row-cols-lg-1 justify-content-center">
        <?php if ( $want_to_sell->have_posts() ) : ?>
            <?php while ( $want_to_sell->have_posts() ) : $want_to_sell->the_post(); ?>
                <?php include get_template_directory() . '/includes/containers/marketplace-sell-artist-page.php'    ;?>
            <?php endwhile;?>
            <?php else: ?>
        <?php endif; ?>
        <?php wp_reset_query(); ?>
    </div>
</div>

1 Answer 1

1

I already got it. Was missing an extra array() in the meta_query.

My updated code is this:

I'd like to thank this website. Sometimes just posting the question helps me figure it out. What a cool community. Good luck and happy coding, all.

<?php
    $artist_id = get_the_ID();

    $want_to_sell = new WP_Query( array(
    'post_type' => 'want-to-sell-post',
    'posts_per_page' => 5,
    'meta_query' => array(
        array(
            'key'     => '_wpcf_belongs_artist_id',
            'value'   => $artist_id,
            'compare' => '=',
        ),
    ), 
));  
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.