首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elementor Pro -自定义查询

Elementor Pro -自定义查询
EN

Stack Overflow用户
提问于 2019-08-17 17:36:30
回答 2查看 1.5K关注 0票数 0

我需要些帮助。我正在尝试为我在Wordpress中创建的自定义帖子创建一个自定义查询,并使用Elementor Pro。

在我的帖子中,我添加了一个带有数值的自定义字段‘排序’,我想用它来手动对帖子进行排序。

然而,我似乎不能让它工作。

我使用的是最新的Elementor pro版本。

我试着按照他们的页面上的说明去做:https://developers.elementor.com/custom-query-filter/

以下是我添加到主题的functions.php文件中的代码

代码语言:javascript
复制
// 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。

EN

回答 2

Stack Overflow用户

发布于 2019-11-27 06:06:11

你已经很接近了。你遗漏了一件事(如果我掌握了你想要做的事情)。

它应该看起来像这样:

代码语言:javascript
复制
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' );
} );
票数 1
EN

Stack Overflow用户

发布于 2021-08-16 20:12:39

您必须再添加两行代码:

代码语言:javascript
复制
// 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');
  });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57535087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档