Home>
I want to check the existence of an article from two pieces of information ($post_info1, $post_info2). Is WP_Query faster than the following get_posts?
// Check existence
$exist = get_posts (array (
'post_type' =>'post',
'meta_query' =>array (
'relation' =>'AND',
array (
'key' =>'key1',
'value' =>$post_info1,
'type' =>'CHAR',
'compare' =>'='
),
array (
'key' =>'key2',
'value' =>$post_info2,
'type' =>'CHAR',
'compare' =>'='
)
),
));
I only know that the information to be acquired is different, and that get_posts is via WP_Query, but I'm not sure how to use it, so I'd like to tell you about that.
Thanks for your understanding.
-
Answer # 1
Related questions
- php : How to check for a completed WooCommerce order
- php - about wordpress and javascript jquery
- php - buddypress activity posting time is off between new posts and thread replies
- php - importing images with wordpress (using acf)
- php - i want to make the editor gutenberg with a custom post
- php - i want to hide the header image only on the post page
- php - how to sort and sort with add_query_arg when creating a loop with wordpress wp_query
- the cause is the php setting, but i just can't figure it out
- php - how to run a program from outside the theme with wordpress
- is it possible to put php code in {} in an if statement?
I don't think it will change.
Depends on the specification method (contents). I think that it does not change greatly with the degree that some default values are different.
【get_posts () | Function | WordPress Developer Resources】
https://developer.wordpress.org/reference/functions/get_posts/
I think it depends on people. I often use WP_Query, but the reporter of the following article seems to use get_posts.
[So far! Exploring the characteristics of [WP_Query] and [get_posts ()] in WordPress | Web production company LIG in Tokyo Ueno]