add_action('wp_ajax_get_all_jobs', 'get_all_jobs_callback');
add_action('wp_ajax_nopriv_get_all_jobs', 'get_all_jobs_callback');
function get_all_jobs_callback(){
/*echo "";
print_r($_POST);*/
$paged = sanitize_text_field($_POST['pageno']);
$job = sanitize_text_field($_POST['job']);
$department = sanitize_text_field($_POST['department']);
$location = sanitize_text_field($_POST['location']);
$tax_query = array();
if($department){
array_push($tax_query,
array(
'taxonomy' => 'by-department',
'terms' => $department,
'field' => 'slug',
)
);
}
if($location){
array_push($tax_query,
array(
'taxonomy' => 'by-location',
'terms' => $location,
'field' => 'slug',
)
);
}
if($tax_query){
$args = array(
'post_type' => 'jobs',
'posts_per_page' => -1,
'post_status' => 'publish',
'paged' => $paged,
'tax_query' => $tax_query,
'post__in' => array($job)
);
if($job == ""){
unset($args['post__in']);
}
}
else{
$args = array(
'post_type' => 'jobs',
'posts_per_page' => -1,
'post_status' => 'publish',
'paged' => $paged,
'post__in' => array($job)
);
if($job == ""){
unset($args['post__in']);
}
}
$loop = new WP_Query( array_filter($args) );
if($loop->have_posts()){
while ($loop->have_posts()) {
$loop->the_post();
?>
Another Example
'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'is_featured',
'value' => 1,
'compare' => '='
)
)
);
$careers = new WP_Query($careerqry);
if($careers->have_posts()){
while ($careers->have_posts()) {
$careers->the_post();
$featured_img_url = get_the_post_thumbnail_url();
?>