Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @muhibbi,

    Have you checked this FAQ yet?: How does WordPress Popular Posts pick my posts’ thumbnails? If you have and you’re still unable to get WPP to display your images I’m going to ask you to share more details so I can help you out.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Marking as resolved due to inactivity.

    Thread Starter muhiBBi

    (@muhibbi)

    No solution was provided. Because I am aware of the thumbnail selection options of the plugin. I choose the Customfields option. I enter the custom field ID I use. But it can’t pick the thumbnail. It can only pick the featured image. I also tried it with the ACF plugin, but it didn’t.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Alright, please share your site’s URL so I can have a look.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Question: what does your custom field return? Is it an image URL? An array?

    Thread Starter muhiBBi

    (@muhibbi)

    The site is in beta. Site: https://beta.yargikararlari.net/

    I create custom fields using the CustomPress plugin. But I also tried using ACF, it didn’t. When I select custom fields as the pick up and enter the custom field ID I use, it doesn’t show any pictures.

    Screenshot: https://pasteboard.co/J3RWTC0.jpg

    Plugin Author Hector Cabrera

    (@hcabrera)

    Alright, how about the question I asked before? What does your custom field return as a value?

    Thread Starter muhiBBi

    (@muhibbi)

    I don’t know.

    I can edit whenever I want to place it on the theme: “<?php echo do_shortcode(‘[ct id=”_ct_upload_5e5d4f020bb15″ property=”title | description | value | link | image”]’); ?>”

    But when I select it in the Popular Posts plugin, I don’t know how it pick up.

    When I write a new post, I upload a new image as customfields

    • This reply was modified 4 years, 11 months ago by muhiBBi.
    Plugin Author Hector Cabrera

    (@hcabrera)

    I don’t know.

    When I write a new post, I upload a new image as customfields

    Fair enough.

    If your custom field doesn’t return an image URL -which I guess that’s probably the case- then WPP won’t be able to display your selected thumbnail.

    Please check with the CustomPress developers how to programatically retrieve the image you select via custom field so you can use it elsewhere and report back their response so I can help you out.

    Thread Starter muhiBBi

    (@muhibbi)

    Okay, but although I have selected the image url option in ACF, it still cannot pick.

    https://snipboard.io/7fDWPY.jpg

    • This reply was modified 4 years, 11 months ago by muhiBBi.
    • This reply was modified 4 years, 11 months ago by muhiBBi.
    Plugin Author Hector Cabrera

    (@hcabrera)

    Ah, that’s the problem then.

    When you select the Image URL option in ACF, ACF stores in the database the attachment ID of the image instead of the image URL. That’s why WPP doesn’t display your image: the value coming from your custom field isn’t an image URL, it’s an integer number.

    To have WPP use the images you set via ACF:

    1. Go to Plugins > Plugin Editor and select WordPress Popular Posts.

    2. Click on src/Image.php to edit this file.

    3. Find this block of code (around line 186) and replace it with this:

    if ( ! $thumb_url || ! $this->is_image_url($thumb_url) ) {
        // Is this an attachment ID instead of an image URL?
        $thumb_url = $thumb_url && Helper::is_number($thumb_url) ? wp_get_attachment_image_src($thumb_url, 'full') : null;
        $thumb_url = is_array($thumb_url) ? $thumb_url[0] : null;
    }
    
    if ( $thumb_url ) {
        /**
            * Filters CSS classes assigned to the thumbnail
            *
            * @since   5.0.0
            * @param   string  Original ALT attribute
            * @param   int     The post ID
            * @return  string  The new ALT attribute
            */
        $alt = apply_filters(
            'wpp_thumbnail_alt_attribute',
            '',
            $post_object->id
        );
    }

    4. Next, find this block of code (around line 259) and replace that with this:

    if ( ! $thumb_url || ! $this->is_image_url($thumb_url) ) {
        // Is this an attachment ID instead of an image URL?
        // If so, try to fetch the image
        $thumb_url = $thumb_url && Helper::is_number($thumb_url) ? wp_get_attachment_image_src($thumb_url, 'full') : null;
        $thumb_url = is_array($thumb_url) ? $thumb_url[0] : null;
    }
    
    if ( $thumb_url && $this->is_image_url($thumb_url) ) {
        $file_path = $this->url_to_path($thumb_url, $post_object->id);
    }

    5. Click on the Update File button to save changes.

    That should do the trick.

    Thread Starter muhiBBi

    (@muhibbi)

    Yes, it worked for ACF. It doesn’t work for the CustomPress plugin, but this is due to that plugin. I wish it worked for CustomPress too. In this case, I will have to use two different plugins.

    Thank you for your help.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Pick images from custom fields’ is closed to new replies.