按作者指定的顺序对 ACF 关系字段进行排序

问题描述 投票:0回答:1

我希望实现与本文所述相同的功能:https://support.advancedcustomfields.com/forums/topic/order-by-sorting-in-relationship-field/

如上面的链接所示,我希望按照它们添加到关系字段的顺序(或随后通过拖放重新排序)在前端显示相关帖子。

我已经在

functions.php
文件中添加了代码,但它似乎不起作用。 如何按照作者指定的顺序对 ACF Relationship 字段进行排序?

wordpress field relationship advanced-custom-fields
1个回答
0
投票

我也在 Elementor 上搜索过这个,我找到了这个。

https://developers.elementor.com/docs/hooks/custom-query-filter/

请将此代码添加到您的主题

function.php
文件中。

/**
 * Order the posts in the query by post__in.
 * @since 1.0.0
 * @param \WP_Query $query The WordPress query instance.
 */
function my_query_by_different_order( $query ) {
    $query->set( 'orderby', 'post__in' );
}
add_action( 'elementor/query/YOUR_QUERY_NAME', 'my_query_by_different_order' );

并添加 YOUR_QUERY_NAME like this.

© www.soinside.com 2019 - 2024. All rights reserved.