我需要些帮助。我正在尝试为我在Wordpress中创建的自定义帖子创建一个自定义查询,并使用Elementor Pro。
在我的帖子中,我添加了一个带有数值的自定义字段‘排序’,我想用它来手动对帖子进行排序。
然而,我似乎不能让它工作。
我使用的是最新的Elementor pro版本。
我试着按照他们的页面上的说明去做:https://developers.elementor.com/custom-query-filter/
以下是我添加到主题的functions.php文件中的代码
// Showing posts ordered by comment count in Posts Widget
add_action( 'elementor/query/speaker_order', function( $query ) {
// Here we set the query to fetch posts with
// ordered by comments count
$query->set( 'orderby', 'sorting' );
} );我已经在Elementor Editor中添加了'speaker_order‘作为查询ID。
发布于 2019-11-27 06:06:11
你已经很接近了。你遗漏了一件事(如果我掌握了你想要做的事情)。
它应该看起来像这样:
add_action( 'elementor/query/speaker_order', function( $query ) {
// Here we set the query to fetch posts with
// ordered by comments count
$query->set( 'meta_key', 'sorting' );
$query->set( 'orderby', 'sorting' );
} );发布于 2021-08-16 20:12:39
您必须再添加两行代码:
// Showing posts ordered by comment count in Posts Widget
add_action( 'elementor/query/speaker_order', function( $query ) {
$query->set('meta_key','sorting');
$query->set('orderby', 'sorting');
$query->set('orderby','ASC');
});https://stackoverflow.com/questions/57535087
复制相似问题