Undefined offset: 0-wp-includes/meta.php:488 -Melding

You should change $parents[] to $parents in get_parents() function: $parents = get_metadata(‘post’, $post_id, WPKWP::$META_CHILD, false); if ($parents !== FALSE && count($parents) > 0) return $parents; return false; because get_metadata return array in this case. If the $post_id parameter is invalid, false is returned. If the meta value isn’t set, function return an empty array. Therefore, … Read more

Sort by presence of thumbnail

Easy peasy! $args_for_query1 = [ ‘post_type’ => ‘custom_project’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘_thumbnail_id’ ) ) ]; $args_for_query2 = [ ‘post_type’ => ‘custom_project’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘_thumbnail_id’, ‘meta_compare’ => ‘NOT EXISTS’, ]; $query1 = new WP_Query($args_for_query1); $query2 = new WP_Query($args_for_query2); $wp_query = new WP_Query(); $wp_query->posts = array_merge( $query1->posts, $query2->posts … Read more

meta query or with meta value

‘meta_key’ => ‘clpr_topcoupon’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ You can solve the problem by using order by clause then there will no need to write meta query. Please use the above code to solve your problem.It will show the posts according to descending order of the value in meta key.

Issues with search after added meta_query

There is one problem with your query. You assume, that it will use OR relation to all query parts. But it won’t. The OR operator will be used only for meta_query parts. It means, that your query is looking for posts that are matching these criteria: (post_title LIKE query) AND ( ean LIKE query OR … Read more

Appending to existing WP_Query’s meta_query if exists

You can use the WP_Query::get method to get whatever is in the meta query like this: add_action(‘pre_get_posts’,’add_another_meta_query’); function add_another_meta_query($query){ //Be sure to only use the main query on frontend if($query->is_main_query() && !is_admin()){ $meta_query = $query->get(‘meta_query’,array()); $new_meta_query = array(); //now, $meta_query has the meta_query if set (or an array) //check if the old version of meta_query … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)