Setting proper query for multiple custom admin filters

This is my final working piece of code: function wpr_manager_filter($query) { global $pagenow; global $typenow; $current_page = isset( $_GET[‘post_type’] ) ? $_GET[‘post_type’] : ”; if ( is_admin() && ‘properties’ == $typenow && ‘edit.php’ == $pagenow ) { $queryParamsCounter = 0; if (isset( $_GET[‘city-filter’] ) && $_GET[‘city-filter’] != ‘-1’) { $cityId = (int)$_GET[‘city-filter’]; $queryParamsCounter++; } if … Read more

WordPress custom slug (endpoint) and compare all links

All of the API functions that generate links have filters to let you alter the output. Here’s a quick example that covers most of them: function wpd_endpoint_links( $url ){ if( isset( $_COOKIE[‘lang’] ) ){ $url = $url . $_COOKIE[‘lang’] . “https://wordpress.stackexchange.com/”; } return $url; } add_filter( ‘post_link’, ‘wpd_endpoint_links’ ); add_filter( ‘page_link’, ‘wpd_endpoint_links’ ); add_filter( ‘post_type_link’, … Read more

Get amount of CPT with a certain custom field value

Well, it returns wrong number, because you’ve coded it exactly in that way 😉 Your WP_Query is correct. So when there are no posts matching your conditions, then you get 0. But when there are such posts, then… you ignore the query completely and return wp_count_posts as result… But… This function returns an object, whose … Read more

Assigning a meta_query value based on regexp to wp_query fails

Meta query should be an array of arrays (every array contains one condition). So instead of $meta_query = array( ‘key’ => ‘offer’, ‘value’ => $off, ‘compare’ => ‘=’ ); $query->set( ‘meta_query’, $meta_query ); There should be $meta_query = array( array( ‘key’ => ‘offer’, ‘value’ => $off, ‘compare’ => ‘=’ ) ); $query->set( ‘meta_query’, $meta_query ); … Read more

Set Transient does nothing

And that exactly how it will work, because that’s what you coded 😉 You set the transient correctly, but… You put only query arguments in there. And that doesn’t make much sense – it’s just an PHP array that is very easy and quick to create. And the query itself is executed always – it’s … Read more

need to exclude APP_TAX_STORE => $term->slug

The easiest way I can see is to gather a list of the terms in that taxonomy, and use them with a NOT IN operator in your query’s tax_query: // Get all the terms in your custom taxonomy. $slugs = get_terms( [ ‘taxonomy’ => ‘industry’, ‘fields’ => ‘slugs’, ] ); $posts = query_posts( [ ‘post_type’ … Read more

Create A Loop With A Variable Number of Posts For Each Bootstrap Row?

The easy-but-a-bit-hacky way to get there would be to initialize a counter variable before your loop and then use that to tell what post you’re on. something like so: $paged = (get_query_var(‘paged’)) ? absint(get_query_var(‘paged’)) : 1; $args = array( ‘post_type’ => ‘workshop’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 11, ‘paged’ => $paged, ); $customQuery = new … Read more