I'm trying to sort the custom posts based on meta value as priority level1, level2 and level3. I have given a dropdown field in post meta as featured posts, standard posts and basic posts. I want to display them as featured posts on top, then standard posts and then basic posts. I tried with below code but it's not sorting the posts in the order.
Any guidance or advise much appreciated!
Here is my code:
Array(
'name' => __( 'Listing Type Options', 'text-domain' ),
'id' => 'lising_type_options',
'type' => 'select',
'child_of' => '',
'options' => array(
'' => 'Select Listing Type',
'1' => 'Basic',
'2' => 'Standard',
'3' => 'Featured',
),
'desc' => ''
),
if( isset( $lp_type ) && !empty( $lp_type ) ){
if( $lp_type == '3' ){
$lp_type = 'Featured';
} elseif( $lp_type == '2' ){
$lp_type = 'Standard';
} elseif( $lp_type == '1' ){
$lp_type = 'Basic';
}
} else{
$lp_type = '';
}
This is the query:
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => $postsonpage,
'paged' => $paged,
'post__not_in' =>$ad_campaignsIDS,
'tax_query' => $TxQuery,
// 'meta_key' => $MtKey,
// 'orderby' => $lporderby,
// 'order' => $lporders,
'order' => 'DESC',
'orderby' => 'meta_value',
'meta_query' => array(
'relation' => 'OR',
$MtKey,
array(
'relation' => 'OR',
array(
'key' => 'lp_listingpro_options',
'value' => 'lising_type_options',
'compare' => 'LIKE',
),
array(
'key' => 'lp_listingpro_options',
'value' => 'lising_type_options',
'compare' => 'NOT LIKE',
),
),
),
);
$MtKey
afterrelation => 'OR'
is throwing me.... ...what is that and why is it there? I don't see anything in your code that defines that variable and I also don't understand why it's dropped in the middle of your query.