首页 > 解决方案 > 使用 Elementor 插件和自定义查询难度按 Wordpress 中的大多数视图/热门帖子排序

问题描述

我有这个代码:

// Posts or Portfolio Widget
add_action( 'elementor/query/my_custom_filter', function( $query ) {
    // Modify the posts query here
} );

来源:https ://developers.elementor.com/custom-query-filter/

并且需要调用 my_custom_filter 查询来排序:

get_option( 'stats_cache' );

这将排列如下:

array(
    ['7375996b7a989f95a6ed03ca7c899b1f'] => array(
        [1353440532] => array(
            [0] => array(
                ['post_id'] => 0
                ['post_title'] => 'Home page'
                ['post_permalink'] => 'http://www.example.com/'
                ['views'] => 1132
            )
            [1] => array(
                ['post_id'] => 4784
                ['post_title'] => 'Hello World!'
                ['post_permalink'] => 
                ['views'] => 493
            )
            /* till item [9] */

或者这个(我托管在 wp 上并运行 jetpack --- 这实际上是首选):

if( function_exists( 'stats_get_csv' ) ) {
    $top_posts = stats_get_csv( 'postviews', 'period=month&limit=30' );
}

这将返回:

array(
    [0] => array(
        ['post_id'] => 0
        ['post_title'] => 'Home page'
        ['post_permalink'] => 'http://www.example.com/'
        ['views'] => 6806
    )
    [1] => array(
        ['post_id'] => 8005
        ['post_title'] => 'Hello World!'
        ['post_permalink'] => 
        ['views'] => 1845
    )           
    /* till item [29] */

来源:如何在 Wordpress JetPack 中查询帖子的查看次数?

我创建了自定义查询 ID -

( 'elementor/query/my_custom_filter', function( $query )

但我不确定如何使用这两个功能:

  1. get_option( 'stats_cache' );
  2. if(function_exists('stats_get_csv')) { $top_posts = stats_get_csv('postviews', 'period=month&limit=30'); }

或在哪里/如何在此处插入它们:

// Posts or Portfolio Widget
add_action( 'elementor/query/my_custom_filter', function( $query ) {
    // Modify the posts query here
} );

查询工作。

我试图将 jetpack 功能粘贴到内部,但没有成功,我尝试'orderby', $top_posts或调用$top_posts = $query但没有成功,还有一堆其他的东西,但没有任何效果,肯定不会在这里做某事。

标签: phpwordpresspluginselementorjetpack

解决方案


推荐阅读