Custom query return

Okay i’m going to try to add this as an answer because I can’t do codes in comments: <?php if($_GET[‘colour’] && !empty ($_GET[‘colour’])) { $colours= $_GET[‘colour’]; //notice i pluralized. } ?> //your code ended php, so i assume there is something here as it is not started again. $meta_query = array(‘relation’ => ‘OR’); foreach ($colours … Read more

Random order of the 5 most popular posts

You’re using the order parameter incorrectly for WP_Query. order (string | array) – Designates the ascending or descending order of the ‘orderby’ parameter. Defaults to ‘DESC’. An array can be used for multiple order/orderby sets. ‘ASC’ – ascending order from lowest to highest values (1, 2, 3; a, b, c). ‘DESC’ – descending order from … Read more

Only show current category post

Use the function get_the_category(); inside the WordPress loop and pass the get_the_ID() function which will get the current post ID in the loop. get_the_ID() will return the post id and whereas the the_id(); will just display. if( $the_query->have_posts() ) : while( $the_query->have_posts() ) : $the_query->the_post(); $category_array = get_the_category( get_the_ID() ); print_r( $category_array ); endwhile; endif; … Read more

WP Query issue for multiple values

You use $args but it isn’t define. IN your form, you need to add double bracket to make $colours an array. <INPUT TYPE=”checkbox” NAME=”colour[]” VALUE=”red”> Red<BR> <INPUT TYPE=”checkbox” NAME=”colour[]” VALUE=”blue”> Blue<BR> $value){ $colours[]=$value; } $meta_query = array(‘relation’ => ‘OR’); foreach ($colours as $colour) { $meta_query[] = array( ‘key’ => ‘colour’, ‘value’ => $colour, ‘compare’ => … Read more

Track write actions to the database

Seems like there’s a plugin out there that does quite this! It’s VersionPress! In this blog post is explained what they used to track all the complicated changes. Instead of using the ‘query’ filter they use the option to create a db.php file in the wp-contents directory to extend $wpdb like explained in this post: … Read more

Problem with custom WP_Query and underlying pagination/posts_per_page

Stop overriding the default loop and use pre_get_posts instead. Like this: function wpse_247208_custom_category_query( $query ) { // Return early for any situation you aren’t interested in. if ( is_admin() || ! $query->is_main_query() || !is_category() ) { return; } $query->set( ‘posts_per_page’, 6 ); // Don’t use a global; create a function to populate this value // … Read more