php - 使用 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 )
但我不确定如何使用这两个功能:
get_option( 'stats_cache' );
- 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
但没有成功,还有一堆其他的东西,但没有任何效果,肯定不会在这里做某事。
解决方案
推荐阅读
- bash - awk 和 sed 命令范围匹配模式中的特殊字符
- android - Android Room 在订阅中返回 Dao 中的 LiveData
- python - 元素从 display: none 变为 display:block selenium python
- android - 如何在flutter中使用flutter_webview_plugin和AndroidX
- json - Groovy:转义较低级别的 JSON
- r - 基于 R 中的两个 grep() 命令寻址 data.table 列
- css - 用于 2k 分辨率屏幕和 4k 分辨率屏幕和 8k 分辨率的响应式 CSS
- c# - Unity 3D,如何生成对象并修改它们的值?
- node.js - GraphQLError:类型查询必须定义一个或多个字段。使用类型鹅
- android - Android:以编程方式在网站的输入字段中输入文本?