0

I have created a CPT

function create_themes_posttype_raihan() {

    register_post_type( 'themes',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'Themes' ),
                'singular_name' => __( 'Theme' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'themes_wallpaper'),
            'supports' => array( 'thumbnail', 'title', 'editor', 'custom-fields' )
        )
    );
}
// Hooking up 
add_action( 'init', 'create_themes_posttype_raihan' );

This works fine. In the loop I can fetch every content but wp_get_attachment_image_srcset returns false.

<?php
while ($query->have_posts()) {
    $query->the_post();
    $imageBanner = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
    $content = get_the_content();
    $size = 'medium';
    $imgSrcset = wp_get_attachment_image_srcset( $post->ID, $size);
    var_dump($imgSrcset); //returns false but others work
}
?>

I want something similar " https://example.com/wp-content/uploads/2019/05/img_1-768x654.png 768w, https://example.com/wp-content/uploads/2019/05/img_1-300x256.png 300w, https:/example.com/wp-content/uploads/2019/05/img_1.png 845w " so that my image can be responsive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.