【发布时间】:2021-08-17 21:54:26
【问题描述】:
我不熟悉 PHP,但尝试在 theme/functions.php 中插入代码 sn-p。我的目的是根据事件自定义帖子类型和自定义字段查询一些帖子。
add_action( 'elementor/query/events', function( $query ) {
$args = array(
'post_type' => 'event',
'meta_query' => array(
array(
'key' => 'dstart',
'type' => 'DATE',
'value' => date('Y-m-d'),
'compare' => '>'
),
),
);
$query->set($args);
} );
但它有这样的错误:
Uncaught ArgumentCountError: Too few arguments to function WP_Query::set(), 1 passed in wp-content/themes/hello-theme-child-master/functions.php on line 46 and exactly 2 expected in wp-includes/class-wp-query.php:1752
Stack trace:
#0 wp-content/themes/hello-theme-child-master/functions.php(46): WP_Query->set(Array)
#1 wp-includes/class-wp-hook.php(294): {closure}(Object(WP_Query))
#2 wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters('', Array)
#3 wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#4 wp-content/plugins/elementor-pro/modules/query-control/classes/elementor-post-query.php(373): do_action('elementor/query...', Object(WP_Query), Object(ElementorPro\Modules\Posts\Widgets\Posts))
#5 wp-includes/class-wp-hook.php(292): ElementorPro\Modules\QueryControl\Classes\Elementor_Post_Query->pre_get_posts_query_filter(Object(WP_Query))
#6 /var/www/
我能知道我误解了哪些部分吗?谢谢。
【问题讨论】:
标签: php wordpress advanced-custom-fields elementor