How to remove duplicate query on page load or make them cacheable
How to remove duplicate query on page load or make them cacheable
How to remove duplicate query on page load or make them cacheable
You can try something like this: <?php $tags_array = get_tags(); $news_query = new WP_Query; foreach ( $tags_array as $tags ) : $news_query->query( array( ‘cat’ => $tags->term_id, ‘posts_per_page’ => 1, ‘no_found_rows’ => true, ‘ignore_sticky_posts’ => true, )); ?> <h2><?php echo esc_html( $tags->name ) ?></h2> <?php while ( $news_query->have_posts() ) : $news_query->the_post() ?> <div class=”post”> <?php the_title() … Read more
Mysql / WordPress killing my server with 80k users [closed]
The difference is what is returned. The WPDB query() method returns true for CREATE, ALTER, TRUNCATE and DROP queries, an integer of how many results for all other queries, or simply false if if there’s an error. The WPDB get_results() method actually returns the entire result of the query (like you would get running the … Read more
You need to use get_posts(), have_posts(), and the_post() for the API functions to work.
Not possible with an empty value. See: How can I show posts only if meta_value is not empty
I’ve been using the following plugin for Event management, and it has short code to display all events and sort them by date. It also has some developer features to give you a bit more control over things. http://wordpress.org/extend/plugins/events-manager/ Very cool plugin that is actively developed.
I don’t think there’s an easy to sort by three different meta values, and really, I don’t see why you need to in this case. Why not just save the event date in one meta value and sort by that? It makes your query much more efficient (removes two unnecessary joins) and lets you use … Read more
If I understand your question correctly, this should work: function get_event_info($event_id = 0, $info = ” ) { global $wpdb; return $wpdb->get_col( $wpdb->prepare( “SELECT meta_value from $wpdb->postmeta WHERE meta_key = ‘%s’ AND post_id IN (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = ‘event_id’ AND meta_value= %s )”, $info, $event_id ) ); } Use this like … Read more
$yesterday = array ( ‘year’ => date(‘y’), ‘month’ => date(‘m’), ‘day’ => date(‘d’)-1 ); $rows = $wpdb->query($wpdb->prepare(*emphasized text* “SELECT id, yymmdd FROM plugin_data WHERE yymmdd LIKE ‘%d-%d-%d”, $yesterday[‘year’], $yesterday[‘month’], $yesterday[‘day’] )); foreach ( $rows as $r ) { $id_for_yesterday_rows[]= $r->id; } Now you have all ids or rows that were submitted yesterday in an array.