Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress通过特色图片URL获取自定义帖子类型类别_Wordpress - Fatal编程技术网

wordpress通过特色图片URL获取自定义帖子类型类别

wordpress通过特色图片URL获取自定义帖子类型类别,wordpress,Wordpress,我的代码是 $args='job_listing_category'; $recent_posts = get_terms ( $args ); print_r($recent_posts); if ( $recent_posts ) { $recent_listing = array(); foreach ( $recent_posts as $value ) { echo $post_thumbnail_id = get_post_thumbnail_id( $

我的代码是

$args='job_listing_category';
$recent_posts = get_terms ( $args );
print_r($recent_posts);
if ( $recent_posts ) {
    $recent_listing = array();
    foreach ( $recent_posts as $value ) {
       echo $post_thumbnail_id = get_post_thumbnail_id( $value['ID'], 'medium' );
        $feat_image = wp_get_attachment_image_src( $post_thumbnail_id );
        $feat_ext = explode(".", (string) $feat_image[0]);
        $feat_name = explode("-150x150", (string) $feat_image[0]);
        $feat_ext = end($feat_ext);
        $feat_image = $feat_name[0] . '.' . $feat_ext;

        $value['image'] = $feat_image;

           $result[] = $value;

          //$recent_listing[] = $category;
    }
} 
print_r($result);

但是没有工作,我没有得到自定义文章类型类别的图像。

如下更改代码。必须在参数中传递自定义post类型

$taxonomies = array( 
    'your_custom_post_type',
    'job_listing_category',
);
$args = array(
  'orderby'                => 'name',
  'order'                  => 'ASC',
);
$recent_posts = get_terms($taxonomies, $args);
print_r($recent_posts);
if ( $recent_posts ) {
    $recent_listing = array();
    foreach ( $recent_posts as $value ) {
       echo $post_thumbnail_id = get_post_thumbnail_id( $value['ID'], 'medium' );
        $feat_image = wp_get_attachment_image_src( $post_thumbnail_id );
        $feat_ext = explode(".", (string) $feat_image[0]);
        $feat_name = explode("-150x150", (string) $feat_image[0]);
        $feat_ext = end($feat_ext);
        $feat_image = $feat_name[0] . '.' . $feat_ext;

        $value['image'] = $feat_image;

        $result[] = $value;
    }
} 
print_r($result);
有关详细信息: