Support

Account

Home Forums Feature Requests Using a random post id from ‘Relationship' field to force a feature img

Solving

Using a random post id from ‘Relationship' field to force a feature img

  • Hello Elliot & Community,

    I have a super convoluted question … I am using the ‘Relationship’ field to popular a single post type with information…

    The single post type itself is completely empty aside from the meta from the data within the relationship field.

    My issue is that I need this (empty) single post to have a featured image and would desire if this were automatically populated from the ‘Relationship’.

    Question:

    Is it possible to randomly query a post id from a relationship field, get that relationship’s featured image and us as its own featured image?

    This would save my publisher allot of work as they are publishing new posts everyday and have an option to select a relationship of about 200+ possibilities.

    I know, sounds crazy? Any suggestions you can provide would be much appreciated.

  • Hi @Jayson

    Yes, this is very possible.

    Find any code in your theme which displays the featured thumbnail for the post, and add in some custom code which loads the ACF relationship value, selects a random array piece and loads that post’s thumbnail.

    Thanks
    E

  • Hi Elliot,

    I am not trying to display this image, I need this to work with a third party api. Bufferapp.com + WP to Buffer.

    It used the stored featured image to attach when broadcasting a post to twitter and facebook. I guess I should have included my full intention 🙂

    Hoping to use the

    set_post_thumbnail() function

    Not sure how possible this would be…

  • Hi @Jayson

    Perhaps you want to use the acf_update_value filter to hook in and run some custom functionality when you save the relationship value.

    you could select a random ID (from $value) and then set_post_thumbnail of the current post based on this.

    Thanks
    E

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Using a random post id from ‘Relationship' field to force a feature img’ is closed to new replies.