カテゴリリストメニューからPostType全一覧

/*
/カテゴリリストメニューからPostType全一覧
*/
function get_all_list(){

$ctgname = $_POST[‘ctgname’];
$posttype = $_POST[‘posttype’];

$args = array(

‘numberposts’ => -1, //表示する記事の数
‘post_type’ => $posttype, //投稿タイプ名
‘orderby’ => ‘rand’,

);

$customPosts = get_posts($args);

if($customPosts) :

foreach($customPosts as $post) : setup_postdata( $post );

//work content
$img = get_field(‘rs-photo1’,$post->ID);

//$imgurl = array();
$imgurl = wp_get_attachment_image_src($img, $post->ID, ‘medium’);

$rs_area = get_field(‘rs-area’,$post->ID);

$outhtml[] = array(

“posttype” => $posttype,
“alllists” => ‘すべてのリスト’,
“categoryname” => $rs_area[‘label’],
“categoryslug” => $rs_area[‘value’],
“id” => $post->ID,
“title” => get_the_title($post->ID),
“workimage” => $imgurl[0],
“worktext” => get_field(“rs-comment”,$post->ID),
“parmalink” => get_the_permalink($post->ID),

);

endforeach;

else:

$outhtml[] = array(

“categoryname” => ”,
“categoryslug” => ”,
“alllists” => ”,
“id” => ”,
“title” => ‘データはありませんでした。’,
“workimage” => ‘https://www.mysite.jp/wp/wp-content/uploads/2017/12/mysite_noimage.jpg’,
“worktext” => ”,
“parmalink” => ”,

);

endif;

echo json_encode($outhtml, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);

wp_reset_postdata();

die();

}

add_action( ‘wp_ajax_get_all_list’, ‘get_all_list’ );
add_action( ‘wp_ajax_nopriv_get_all_list’, ‘get_all_list’ );