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
1 Answer
Reset to default 0I 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
版权声明:本文标题:Oxygen Repeater Advanced Query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288927a1928197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论