/*
/カテゴリリストメニューからカテゴリ内の全投稿一覧
*/
function get_category_list(){
$ctgid = $_POST[‘ctgid’];
$ctgname = $_POST[‘ctgname’];
$ctgslug = $_POST[‘ctgid’];
$posttype = $_POST[‘posttype’];
$args = array(
‘numberposts’ => -1, //表示する記事の数
‘post_type’ => $posttype, //投稿タイプ名
‘orderby’ => ‘rand’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘genre_’.$posttype,
‘field’ => ‘slug’,
‘terms’ => $ctgslug
)
)
);
$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’);
$outhtml[] = array(
“posttype” => $posttype,
“categoryname” => $ctgname,
“categoryslug” => $ctgslug,
“alllists” => ”,
“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/rishiriplus_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_category_list’, ‘get_category_list’ );
add_action( ‘wp_ajax_nopriv_get_category_list’, ‘get_category_list’ );