Conditional regex in add_rewrite_rule() for specific query filters & pagination

I’ve managed to workaround the problem. He’re the solution for further reference. 1) I have only 1 query var now: function return_vars( $vars ) { $vars[] = ‘filters’; return $vars; } 2) My rewrite rules changed to: add_rewrite_rule( ‘my-base/filters/([^\/]*)/([^&]*)/page/([0-9]{1,})/?’, ‘index.php?post_type=$matches[1]&filters=$matches[2]&paged=$matches[3]’, ‘top’); add_rewrite_rule( ‘my-base/filters/([^\/]*)/([^&]*)/?’, ‘index.php?post_type=$matches[1]&filters=$matches[2]’, ‘top’); Rule 1: handles pagination Rule 2: handles main page only … Read more

How to get customfield value by woocommerce product ID

If you look for all products with same ‘product_cip’ value try this: $a=array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => – 1, ‘meta_query’ => array( array( ‘key’ => ‘product_cip’, ‘value’ => ‘some value’, ‘compare’=> ‘=’ ) ), ‘fields’ => ‘ids’ ); $b=get_posts($a); echo count($b); if you have get all products data $products_array=array(); foreach($b as … Read more

Automatic value for custom fields for posts

Try meta_query to get posts having theme_settings_post_show == true (for new posts) and theme_settings_post_show not set at all (for old posts): <?php $queryArguments = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘OR’, // value is not set or true array( ‘key’ => ‘theme_settings_post_show’, ‘value’ => ”, // can be any … Read more

FacetWP group listings by custom field [closed]

I finally fixed it: <?php $state_posts = array(); while ($query->have_posts()) { $query->the_post(); $state = get_post_meta(get_the_ID(), ‘state’, true); $state_posts[$state][] = $post; } wp_reset_query(); foreach ($state_posts as $state_post => $state_title) { ?> <h1 class=”state-name”><?php echo esc_html($state_post); ?></h1> <?php foreach ($state_title as $listing => $single_listing) { setup_postdata($single_listing); $post_id = $single_listing->ID; $title = get_the_title($post_id); $distance = facetwp_get_distance($post_id); $distance = … Read more

Search Posts with Custom Fields as query

There are few ways to solve this problem… 1. Don’t bother and use Relevansi (or some other similar plugin) You can often hear that using many plugins is a bad thing. It’s not entirely true. It’s bad only if these plugins have big impact on use of resources. In this case, Relevansi won’t cause such … Read more

WordPress CMB2 – Run function on save

If you haven’t gotten the answer to this yet, I found the answer by sifting through the source code. I was able to hook into the post save event by using: cmb2_save_{$object_type}_fields_{$cmb_id}. This hook fires whenever you save a certain object type with a specific metabox ID. So, in your case your $cmb_id is test_metabox, … Read more