Tag Info

Hot answers tagged

5

There is no build in function to achieve what you want, at least not for complicated meta queries like this. If you need to use build in functions for this, the best will be to make use of WP_Query. To make the query faster and to skip the unwanted returned array of WP_Post properties, and because you are only interested in post count, you can use the ...


3

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.


2

The solution: $query = array( 'post_status' => 'publish', 'post_type' => 'product', 'posts_per_page' => 10, 'meta_query' => array( 'key' => '_price', 'value' => array(50, 100), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ), ); $wpquery = WP_Query($query); // return 10 products ...


2

It seems like yes it depends whether it does create a new query or not. As Milo has pointed out in his answer, WordPress using a caching system. The function stack looks like this: get_the_permlink() calls get_permalink() calls get_post() which when given a post ID does this: $_post = WP_Post::get_instance( $post ); which looks like: /** * Retrieve ...


2

There is no way to determine the screen size with PHP (which you would need to do in order to alter that variable). So you have two options: 1) Easy: Use responsive CSS to hide posts 4-10 on smaller screens In your loop, add a condition class to any post after the third post, like this: <?php $count = 0; $args = array( 'numberposts' => '10', ...


1

Yes, there is no way to get screen size with PHP, because it runs on server, while the screen is something related to client (browser). However, in OP you say: for a desktop visitor I show 10 posts and for a mobile visitor I show 3 posts and even if you can't get the screen size, you can understand if the request comes from a mobile device, thanks to ...


1

You're close. Your first attempt is using get_the_tags incorrectly. The function accepts the post ID you want to get the tags from. In your example, there is no $tag global, so $tag->name is trying to fetch a property of a non-object. In your second attempt, a single post won't have any tag-related query vars, that would only be set on a tag archive page ...


1

This is actually a tricky question, as by stating exact there are two ways in which one can interprit your question - Only find posts where the whole title or the whole content match exactly. For example, if you search My post is super you would not have returned a post with the title My post is super awesome. Fine posts where the exact phrase exists, not ...


1

You want to orderby 'date' not by 'meta_value_num' because it is to order numerically. So if you were ordering items by their price, then you would want to use 'meta_value_num'. The meta_key 'news_date' is most likely in date format. You should also cast the meta_value to DATE using 'meta_type' => 'DATE'. $args = array( 'post_type' => 'news', ...


1

Give this a try. It replaces query_posts(), which you should never use (it kills unicorns) with WP_Query. Basically it first queries your sticky posts and then, if there were less than your required 3 posts, it will perform another query for the relavent number of posts. /** Grab the sticky post ID's */ $sticky = get_option('sticky_posts'); /** Query the ...


1

I figured it out: $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => "show_times_%_date", "value" => $this_month . "[0-9]{2}", "compare" => "REGEXP" ) ), ));


1

Make sure you have declared the $wpdb variable global $wpdb;. Also calling $wpdb->query() will execute the query for you, so no need to do it again. I would also recommend using $wpdb->insert() as this escapes your data for you: global $wpdb; $wpdb->insert( $wpdb->prefix . 'fafa', array( 'titile' => trim( ...


1

The following code will properly store data in wp_fafa: $wpdb->insert( $wpdb->prefix . 'fafa', array( 'title' => trim($row->item(0)->nodeValue), 'liveprice' => trim($row->item(2)->nodeValue), 'changing' => trim($row->item(4)->nodeValue), 'lowest' => ...


1

Two options. The first will keep you away from custom SQL, and should be a lot more efficient than what you currently have. It runs two queries, one to get the user ID with the highest hourly rate, and then again to get the lowest. You need one more query to update the user meta cache & then you're home free: $query = new WP_User_Query; $users = array( ...


1

This is untested, but I believe if you set type in your meta query to numeric, that will cast the values as numbers so orderby meta_value should work correctly.


1

Your AJAX callback method should be outputting something followed by a die() statement. function wp_insert() { ..your code echo $whatever_your_results_are; // die(); } I would also recommend against prefixing your custom methods with wp_. That should be reserved for WordPress and will cause confusion to other developers - and probably you ...



Only top voted, non community-wiki answers of a minimum length are eligible