Order posts by more than one variable (meta_key and publish date AND time)

I found this link about “a more powerful ORDER BY in WordPress 4.0” and it led me to try this code: <?php $query = new WP_Query( array( ‘post_type’ => ‘result’, ‘posts_per_page’ => 100, //’paged’ => $paged, ‘meta_key’ => ‘event_date_results’, ‘orderby’ => array( ‘meta_value_num’ => ‘DESC’, ‘post_date’ => ‘DESC’), //’order’ => ‘DESC’, ‘meta_value’ => date(‘Ymd’), ‘meta_compare’ … Read more

Using the same WP_Query for shop and widgets in WooCommerce shop

The reasons your pre_get_posts filter does not work on the widget are the condition !$wp_query->is_main_query() makes the filter handle only the main query and nothing else Your special parameter myattr is “self populating” only on the main query but it is not propagating automatically to other queries. To make it work on the widget, the … Read more

WP_Query causing links to not work

I’m sorry. I didn’t create a single.php file. In my learnings I have discovered that if no single.php file exist then WordPress falls back to index.php. So the link were actually working but just using the same template. Again im sorry for wasting your time.

WP_Query – show posts where meta value and user_email match

Both examples of your code throw errors on the while line: <?php while ( $users_query->have_posts(): $users_query->the_post() ) ?> The while will work if you move the parenthesis from the end to before the colon, and replace the parenthesis with a semicolon. <?php while ( $users_query->have_posts() ) : $users_query->the_post() ; ?> (The Errors turn up fast … Read more

query only returning posts with already set custom field

You can add the custom field to all of the post: $posts = get_posts(array(‘post_type’=>’entity’, ‘posts_per_page’=>-1); foreach($posts as $post){ if(get_post_meta($post->ID, ‘entity_person_relevance’, true) == null ){ $term = wp_get_object_terms( $post->ID, ‘yourtermcat’); // see codex to $wp_error handling or just set $term to 1, 2 or 3 update_post_meta($post->ID, ‘entity_person_relevance’, $term->term_id); } }

modifying the loop multiple times with arguments passed through ajax to wp_query

You can use wp_localize_script to save your current query to JS variable. Then you should send it using ajax and modify it and send it back to have access to it in the future. global $wp_query; wp_localize_script( ‘ajax-pagination’, ‘ajaxpagination’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘query_vars’ => json_encode( $wp_query->query ) )); This article should help … Read more