Applying $posts_clauses filter to specific queries only

I had the same problem of needing to only apply $post_clauses to specific loops/queries and was able to use THIS solution provided by Stephen Harris: You can access query variables (including custom ones) via the WP_Query::get() method. For example: $my_query = new WP_Query( array( … ‘wpse105219_custom_var’ => ‘foobar’, … ) ); To ‘catch’ this at … Read more

pre_get_posts query between 2 dates (date stored in custom post meta)

You can always use a BETWEEN comparison in your query, I have used this, maybe you can adapt it to work in your situation. It avoids doing multiple checks for no reason 🙂 $first_date = 110501; $second_date = 170514; $meta_query = array( ‘key’ => ‘_exm_date’, ‘value’ => array($first_date, $second_date ), ‘type’ => ‘DATE’, ‘compare’ => … Read more

How to display WordPress archive into three columns [closed]

There is a great post here: https://digwp.com/2010/03/wordpress-post-content-multiple-columns/ on how to do just that. The way I use most often is number 3. It’s a bit involved, but here are the steps. For more in depth coverage (which you’ll probably want), check out the post. Add the my_multi_col_v2 function to your functions.php file function my_multi_col_v2($content){ // … Read more

Dashboard :10 Last draft page and 10 last pending review page (metabox)

#dahsboard BOXES #Last edited pages add_action( ‘wp_dashboard_setup’, ‘admin_dashboard_last_edits_register’ ); function admin_dashboard_last_edits_register() { wp_add_dashboard_widget( __FUNCTION__, __( ‘Last published pages ‘, ‘admin-dashboard-last-edits’ ), ‘admin_dashboard_last_edits_dashboard_widget’); } function admin_dashboard_last_edits_dashboard_widget() { $posts = get_posts( array ( ‘numberposts’ => 10, ‘post_type’ => array ( ‘page’ ), ‘orderby’ => ‘modified’) ); if ( $posts ) { $date_format = get_option( ‘date_format’ ); echo … Read more

Display post from current category and same tag?

Tags are a taxonomy called post_tag. You can use them in get_posts() via the tax_query. Since wp_get_post_tags() returns an array of objects, you need to clean it up a bit since only one field per object is required for the query. $tag_objects = wp_get_post_tags($post->ID); $tags = array(); foreach ($tag_objects as $tag_object) { $tags[] = $tag_object->term_id; … Read more

How to display category from recent posts?

You can use get_the_category_list() to output a comma-separated list of links to categories: <?php $args = array( ‘numberposts’ => ‘5’ ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ echo ‘<h2><a href=”‘ . get_permalink($recent[“ID”]) . ‘”>’ . $recent[“post_title”].'</a> </h2> ‘; echo ‘<p>’ . date_i18n(‘d F Y’, strtotime($recent[‘post_date’])) .'</p> ‘; echo get_the_category_list( ‘, ‘, … Read more

How to get the user meta data for a post?

You can pass the post’s author as an argument to get_the_author_meta: get_the_author_meta(‘ID’, $post->post_author); The second argument is the user’s ID. This is stored in the post object in your loop, which you can access it by using $post->post_author. Reason The reason behind the current code of yours that isn’t working is this piece of code … Read more

Post revisions disappeared (for some posts)

Check your database to see if the revisions are still there. Use phpmyadmin or another database tool and go to wp_posts table and search for post_type = revision. If they are not there, they are gone. A lot of “optimization” plugins remove post revisions for you. I would check if any of your plugins has … Read more