Query the post which have a thumbnail
try to work this into your query: ‘meta_key’ => ‘_thumbnail_id’ http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
try to work this into your query: ‘meta_key’ => ‘_thumbnail_id’ http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
I don’t think you need so many transients set, one for each category. You can only use one, that is enough. Transients are quite expensive to set as it requires additional db queries, so you would want to cut down on the use. As always, I like to keep my templates simple, short and sweet, … Read more
After a huge night overthinking this, and thanks to Joost de Valk (Yoast SEO plugin author), I found the solution. As per this thread: https://github.com/Yoast/wordpress-seo/issues/437 , what I want to achieve the way I do, is undoable, or at least, a very bad practice. If you want your custom query to have the default pagination … Read more
I would save an option on post save: add_action( ‘save_post’, function($id,$p) { if ( (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) || (defined(‘DOING_AJAX’) && DOING_AJAX) || ($p->post_status === ‘auto-draft’) ) { return; } update_option(‘_last_site_update’,$p->post_date); }, 1,2 ); And retrieve it with a variant of the function provided by @G-M : function my_last_updated( $format=”” ) { $last = get_option(‘_last_site_update’); if … Read more
Use sessions: <?php session_start(); if( isset( $_POST[‘order’] ){ $order = filter_input( INPUT_POST, ‘order’, FILTER_SANITIZE_STRING ); if( $order ) $_SESSION[‘order’] = $order; } if( isset( $_SESSION[‘order’] ) $order = $_SESSION[‘order’];
You can use a static class property to store a rolling list of posts that are used in previous queries. This method allows you to pass data between classes (widgets, modules, plugins, etc…), but will also work for a procedural workflow. Everything on the page that uses your intermediary class will know what posts to … Read more
SQL query equivalent to WP User Query
The “Order By Rand() Alternative” method You can check out this article that discuss how to optimize SQL queries when selecting N random rows. It’s called Order By Rand() Alternative method. I’ve used it in one of my previous answers. As far as I understand it, the trick is to introduce a special WHERE condition … Read more
Below code is an example that does what you want. See tax_query for more information. function my_get_posts( $query ) { // we only need to modify the query for logged in users if ( !is_user_logged_in() ) return $query; $current_user = wp_get_current_user(); // assuming that user’s region is stored as user_region meta key $user_region = get_user_meta( … Read more
First of all, never use query_posts Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. … Read more