WordPress meta_query >= &

Looks like I found the solution. I needed to use compare instead of operator in the meta_query so array( ‘key’ => ‘vacancy_small_salary’, ‘value’ => $vacancy_small_salary, ‘operator’ => ‘>=’, ‘type’ => ‘NUMERIC’ ), becomes array( ‘key’ => ‘vacancy_small_salary’, ‘value’ => $vacancy_small_salary, ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ), and the same for the other query

Find all product ID from array of customfield

$product = array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘product_cip’, ‘value’ => ‘some value’, ‘compare’ => ‘=’, ) ), ‘fields’ => ‘ids’, ); $product_post = get_posts($product); echo count($product_post); if you have get all products data $products_array = array(); foreach ($product_post as $v){ $_product = wc_get_product($v); echo …

Read more

How To Keep Search Title the same on paged Results

The problem is here: if( get_post_type()==’page’ || is_single() ){ echo ‘<h1 class=”h2″>’. $post->post_title .'</h1>’; } get_post_type() is using the global $post, which will contain the first post in your result set. If this is a page, then your other conditions will never be tested and you’ll never reach the is_search() test. Use is_page() instead: if( …

Read more

How can I insert a new markup element after 4 posts automatically? [closed]

This can be achieved by accessing WP_Query class properties, available while in the loop, like $current_post (index of the current post), $post_count (number of posts displayed), $found_posts (total number of posts matching query). By using $current_post, $post_count and PHP modulo, like shown below: <?php if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); …

Read more

WP_Query: apply an SQL function to meta fileld value

You can use the filter posts_orderby. For a simple example: add_filter(‘posts_orderby’, ‘apply_sql_on_order’, 10, 2 ); function apply_sql_on_order($orderby, $query) { if(is_array($query->query_vars[“orderby”]) && array_key_exists(“apply_sql”, $query->query_vars[“orderby”])) { $orderby = preg_replace(“/(.*) (ASC|DESC)/”, $query->query_vars[“orderby”][“apply_sql”] . “($1) $2”, $orderby); } return $orderby; } $query = new WP_Query( array( ‘meta_query’ => array( ‘state_clause’ => array( ‘key’ => ‘state’ ), ), ‘orderby’ => …

Read more

create metabox to activate slider

Don’t bother with the checkbox and metabox, that’s limiting: You’re only able to have a single slider, and have to add code for every new slider to add a new checkbox Data gets stored in post meta as a custom field, but querying posts by their post meta is super expensive and slow So I …

Read more