Query posts using less than

How about something like this? $args = array( ‘date_query’ => array( array( ‘before’ => array( ‘year’ => 2013, ‘month’ => 2, ‘day’ => 28, ), ‘inclusive’ => true, ), ), ‘posts_per_page’ => -1, ); $query = new WP_Query( $args ); Obviously you could set the exact date from a variable. More info: https://codex.wordpress.org/Class_Reference/WP_Query

How to remove only the latest sticky post from the loop

So if you’re getting the sticky-post you want removed anyways I want to do that coz I will make another query to render the latest sticky post on top of the main loop in a separate ‘div’ Just make a variable, $excludeSticky, with it’s ID, and add an ‘post__not_in’ => array($excludeSticky), argument in your query.

Multiple wp_query on archive page

I’m not entirely sure, but it looks like you need another conditional in your filter. Right now, it filters all content looking for category, tag or date that don’t have the nav_menu_item, mvp_projecvts query variable set for post types. Perhaps you could add a filter to check if some variable is set and only filter … Read more

Wpdb->query result show 1 but is not an integer

I found the solution. The result 1 for my query means true and it’s a boolean so $wpdb->query can return true, not only int|false as it is written above the public function query : wpdb::query PHP code $res = $wpdb->query(“ALTER TABLE ” . $table_name. ” ADD ” . $column_name . ” varchar(35)”); error_log( $res ); … Read more

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

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