How to count get_users query?
when you use get_users() it retrieves an array of users matching the criteria given in $args which means you can simply use PHP’s count() function e.g: $users = get_users($args); $number_of_users = count($users);
when you use get_users() it retrieves an array of users matching the criteria given in $args which means you can simply use PHP’s count() function e.g: $users = get_users($args); $number_of_users = count($users);
You should try applying the s(search) as parameter for your custom query. See this example here: $query = new WP_Query( ‘s=keyword’ ); and you can then apply normal loop to iterate through your results. This also performs string match same as like operator %keyword% you mentioned in comment for @Ravs’ answer. Refer documentation here.
As setup_postdata is messing with global variables that might be (most probably: are) used by other loops (including The Loop), you should always reset these variables to what they should be—according to the main query (i.e., what WordPress thinks the user wanted in the first place). In addition, setup_postdata is provided with (a reference to) … Read more
You do not need to use the post_meta here, as all the Information is available in posts. To insert a new post, use wp_insert_post( $post ), and pass the arguments to your $post-array. This function can return a WP_Error-object for Error handling (if the second argument is set to true, returns 0 on error if … Read more
I’ve never seen it done before but the logic of the PHP IF/ELSE should mean you could simply plug a new query in after the ELSE: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part ( ‘templates/post’, ‘main’ ); endwhile; else: $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : … Read more
Query results for posts, terms, and metadata get placed in cache. If a function is called that accesses data from previously queried objects within the same request (or you’re using a persistent cache mechanism that maintains data across requests), it will not trigger another query and will instead fetch the data from cache.
Fixed query select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = ‘_product_id’ and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta as im where p.post_type=”shop_order” and p.ID = pm.post_id and p.ID = i.order_id and p.post_date BETWEEN ‘2016-01-14 00:00:00’ AND ‘2016-01-14 23:59:59’ … Read more
I should think that you can use phpAdmin Find and Replace where you find “http://www.example.com” and replace with “https://www.example.com“. This should handle all internal linking (if blog, then internal linking as well as images, etc.). It would not cover relative addressing like “//www.example.com”. In the case of WordPress, this would be done on the wp_posts … Read more
In order to achieve a deeper “injection” into the search and catch what the user has searched as soon as possible, we have to look at the WP_Query class and see how it treats a query for posts: In its parse_query function wee that it uses a flag to signal to the whole class that, … Read more
You can get the post ID from the slug with the url_to_postid() function: $ID = url_to_postid(slug); then just exclude the ID from your query: query_posts(array(‘category_name’ => ‘Mycat’, ‘posts_per_page’ => -1, ‘post__not_in’ => $ID )); You can create an array of post IDs if you need to exclude multiple pages.