Tuesday, November 8, 2022
HomeWordPress Developmentwp question - The best way to show posts from a selected...

wp question – The best way to show posts from a selected time period first then one other posts from one other phrases utilizing tax_query


I’m constructing a Customized question to show customized posts ( Jobs publish kind ) from a selected taxonomy ( job location taxonomy ) relying on IP detection. However i would like to question all jobs and show them having these nation ( The IP detected nation) associated to be on the start.

The next question solely will get nation associated jobs, however the right way to prolong this to show detected nation’s posts first

    $args = array(
        'post_type'      => 'noo_job',
        'post_status'    => 'publish',
        'posts_per_page' => 9,
    );

// anony_ip_info is a customized funtion to get the nation identify
$user_country = anony_ip_info(null, 'nation');


if( $user_country && !is_null($user_country) ) 
{
    // Now get phrases which may match detected nation identify
   $term_args = array(
        'taxonomy'               => 'job_location',
        'hide_empty'             => false,
        'fields'                 => 'id=>identify',
        'name__like'             => $user_country,
    );

    $get_term = new WP_Term_Query($term_args);

    if ( !empty($get_term->phrases && is_array( $get_term->phrases )) ) 
    {
        // If there a number of match get the primary
        $user_country_data = noo_array_1st_element($get_term->phrases);

        $term_id = array_keys( $user_country_data )[0];

        $term_name = array_shift($user_country_data);

        $args['tax_query'] = array( 
            array(
                'taxonomy' => 'job_location',
                'phrases'    => array(apply_filters( 'wpml_object_id', $term_id, 'job_location', true ))
            )
        );
    }
}
$question = new WP_Query( $args );
if ( $query->have_posts() ):

endif;

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments