admin管理员组

文章数量:1122832

Looking for some help with a repeater using an advanced query using ACF.

I've got two custom post types: Product, Vendor

Vendor has a sponsored field. Product has a relationship field connected to Vendor

I am trying to sort the Product Archive loop by the sponsored field, so that Vendors that are sponsored have their products show at the top of the list.

I can't for the life of me figure out who that query should be written. It's been like 3 hours of attempting everything to no avail!

Looking for some help with a repeater using an advanced query using ACF.

I've got two custom post types: Product, Vendor

Vendor has a sponsored field. Product has a relationship field connected to Vendor

I am trying to sort the Product Archive loop by the sponsored field, so that Vendors that are sponsored have their products show at the top of the list.

I can't for the life of me figure out who that query should be written. It's been like 3 hours of attempting everything to no avail!

Share Improve this question edited Feb 17, 2022 at 3:41 dcolumbus asked Feb 17, 2022 at 3:26 dcolumbusdcolumbus 6374 gold badges13 silver badges29 bronze badges 1
  • Relationships in ACF are generally implemented as taxonomy. You may find better help in ACF support forums. – Abhik Commented Feb 17, 2022 at 5:31
Add a comment  | 

1 Answer 1

Reset to default 0

I hope this helps

I added comments to the WP_Query array below.

<?php 

// query
$the_query = new WP_Query(array(
    'post_type'         => 'event',  // (the post type / custom post type)
    'posts_per_page'    => -1,
    'meta_key'          => 'featured',  // (acf-field-name-NOT-label)
    'orderby'           => 'meta_value', // (Don't change)
    'order'             => 'DESC' // (or ASC or RAND)
));

?>
<?php if( $the_query->have_posts() ): ?>
    <ul>
    <?php while( $the_query->have_posts() ) : $the_query->the_post(); 
        
        $class = get_field('featured') ? 'class="featured"' : '';
        
        ?>
        <li <?php echo $class; ?>>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endwhile; ?>
    </ul>
<?php endif; ?>

<?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

https://www.advancedcustomfields.com/resources/orde-posts-by-custom-fields/

本文标签: Oxygen Repeater Advanced Query