我正在尝试为使用高级自定义字段插件定义的自定义字段添加新的过滤器。
我想过滤艺术家的年龄,我查阅了一些文档,但在进展中感到困惑。(我是一个wordpress新手)
我已将以下代码行添加到我的functions.php中,遗憾的是没有任何明显的结果。
add_action('graphql_register_types', function () {
$customposttype_graphql_single_name = "artist";
register_graphql_field('RootQueryTo' . $customposttype_graphql_single_name . 'ConnectionWhereArgs', 'age', [
'type' => 'ID',
'description' => __('The ID of the post object to filter by', 'your-textdomain'),
]);
});
add_filter('graphql_post_object_connection_query_args', function ($query_args, $source, $args, $context, $info) {
$post_object_id = $args['where']['age'];
if (isset($post_object_id)) {
$query_args['meta_query'] = [
[
'key' => 'artist_metadata',
'value' => $post_object_id,
'compare' => '='
]
];
}
return $query_args;
}, 10, 5);
Run Code Online (Sandbox Code Playgroud)
我希望实现的是根据年龄字段过滤艺术家,该字段位于由高级自定义字段定义的artist_metadata字段组中,如下图所示。
我似乎在我的代码中找不到setinterval()的正确用法。它应该每秒刷新9种新的随机颜色。
我已经尝试将代码放置在带有嵌套循环的箭头函数中,希望这将为完成的每个循环启动间隔。
但是,这并没有解决任何问题。请参考下面的完整代码:
let test = () => {
for (let i = 0; i <= 9; i++) {
addRandomColorToSquare();
}
}
setInterval(test, 1000);
let addSquareToDOM = function(color) {
let square = document.createElement('div');
square.className = 'square';
square.style.backgroundColor = color;
document.body.appendChild(square);
}
let addRandomColorToSquare = function() {
const randomRed = Math.floor(Math.random() * 256);
const randomGreen = Math.floor(Math.random() * 256);
const randomBlue = Math.floor(Math.random() * 256);
let rgbColor = `rgb(${randomRed}, ${randomGreen}, ${randomBlue})`;
addSquareToDOM(rgbColor);
test();
}Run Code Online (Sandbox Code Playgroud)