“'orderby' => $company_name,
” should be “'orderby' => 'meta_value',
“
If the value of _company_name
is numeric – it should be meta_value_num
.
Note that ‘orderby’ can only have a predefined value and ordering does it alphabetical
See the possible values at the WP_Query orderby parameter: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
The ordering parameter says: Order alphabetical by the values of meta_key
– _company_name
in your case. That is not what your question says.
If you only want posts from a specific company in first place you have to do 2 loops.
One with the $company_name
as you did and one with excluding $company_name
First loops args:
$related_args_company = array(
'post_type' => 'job_listing',
'posts_per_page' => 6,
'post_status' => 'publish',
'post__not_in' => array( $post->ID ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_job_location',
'value' => $job_location,
),
array(
'key' => '_company_name',
'value' => $company_name,
),
),
);
Second loops args:
$related_args = array(
'post_type' => 'job_listing',
'posts_per_page' => 6,
'post_status' => 'publish',
'post__not_in' => array( $post->ID ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_job_location',
'value' => $job_location,
),
array(
'key' => '_company_name',
'value' => $company_name,
'compare' => 'NOT LIKE'
),
),
);
kind regards,
tom