• Resolved carryoncoding

    (@carryoncoding)


    Hi, I’m using the excellent DFI plugin to allocate an image whenever there is no photo on this portfolio.

    I used your recommended code to build the following:

    // Default Feature Image
    // Set for Portfolio posts only
    function dfi_posttype_book ( $dfi_id, $post_id ) {
      $post = get_post($post_id);
      if ( 'portfolio' === $post->post_type ) {
        return 2307; // the image id of RWD logo
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );

    but I have something wrong because this also sets the image for ALL posts without a featured image defined.
    I understood hte code would allow only for CPT of ‘portfolio’.
    Can you see what I am doing wrong?
    Many thanks,
    Phil.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi carryoncoding,

    What I suspect happens.
    In the wp-admin media settings did you set a image? Is that the same as your exception?

    In the code snippet you have 2 cases.
    1) return 2307 this will set the image with ID 2307
    2) return $dfi_id this will set the image you set in media settings.

    If I understand you correctly you want DFI to only work with portfolio and no other posttypes. To do that use this:

    // Default Feature Image
    // Set for Portfolio posts only
    function dfi_posttype_book ( $dfi_id, $post_id ) {
      $post = get_post($post_id);
      if ( 'portfolio' === $post->post_type ) {
        return 2307; // the image id of RWD logo
      }
      return 0; // empty id is no DFI
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10
    
    • This reply was modified 6 years, 3 months ago by Jan-Willem.
    Thread Starter carryoncoding

    (@carryoncoding)

    Thanks Jan, you are absolutely right, that is exactly what I was doing!
    Thank you for correcting my setup.
    Kind regards,
    Phil.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need DFI on one CPT only but appearing on posts’ is closed to new replies.