date_query not returning some posts in date range

Your syntax is incorrect for your date_query. It should be an array of an array, not just an array. I also suspect that your problem might be related to PHP and not WordPress. Your before date is invalid. PHP only supports dates between 13 December 1901 and 19 January 2038, so your dates need to … Read more

get posts based on meta value of the author

Get for all users / authors with user meta field. meta1 = true $args = array( ‘meta_key’ => ‘meta1’, ‘meta_value’ => ‘true’, ‘meta_compare’ => ‘=’, ‘fields’ => ‘all’, ); $users = get_users( $args ); Store user id and login into an array authors $authors = array(); foreach ( (array) $users as $user ) { authors[ … Read more

How-to exclude terms from the main query the most performant way?

You can set the taxonomy query for the main query using pre_get_posts: add_action( ‘pre_get_posts’, ‘my_exclude_terms_from_query’ ); function my_exclude_terms_from_query( $query ) { if ( $query->is_main_query() /* && whatever else */ ) { $tax_query = array ( array( ‘taxonomy’ => ‘category’, ‘terms’ => array( ‘cat-slug’ ), ‘field’ => ‘slug’, ‘operator’ => ‘NOT IN’, ) ); $query->set( ‘tax_query’, … Read more

get comments and get posts in loop

get_comments accepts an array of arguments, you are passing an integer. If you want to retrieve all comments for a post use: get_comments( array(‘post_id’ => $post->ID, ‘status’ => ‘approve’) ); To get an already formatted comment list, is easier use the wp_list_comments() function, instead of another foreach cycle (code from codex): echo ‘<ol class=”commentlist”>’; //Gather … Read more

Using get_posts with arguments found in meta keys

get_posts accepts any of the arguments that WP_Query accepts. So there’s a few options. 1. meta_key and meta_value <?php get_posts(array( // some more args here ‘meta_key’ => ‘some_key’, ‘meta_value’ => ‘some value’ )); 2. meta_query meta_query is more sophisticated that using meta_key and meta_value. For instance, say you wanted to get posts that have the … Read more

How to restore deleted pages/posts?

Then you should see a link “Trash” on the top of pages/posts listing section. Click on that link which will take you the section where all the trashed pages/posts are listed. Select the pages/posts using the checkboxes against them. Select Restore from Bulk Actions dropdown, then hit the Apply button. Now go to pages/posts listing … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)