• amedic

    (@amedic)


    Hello,

    how to filter posts that has og:image?
    It is easy to filter for featured image:

    meta_query' => array(
        array(
        'key' => '_thumbnail_id',
         'compare' => 'EXISTS'
    )

    But how to filter it for posts that have og:image (Facebook image)?

    Also, how to get that image in php with post ID?
    Is there something similar like for thumbnail:
    get_the_post_thumbnail_url()

    Thank you.

    • This topic was modified 6 years ago by amedic.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Joy

    (@joyously)

    There is no such thing, because it is not something that WordPress handles. OpenGraph tags are added to the page output by plugins.

    Moderator bcworkz

    (@bcworkz)

    Joy is correct, but there may still be a custom solution you can implement. It all depends on where the information supplied with the og:image is coming from. That depends on the theme or plugin implementing the open graph tags.

    If this value is indeed saved in post meta and you can identify under which key it is stored, then you could use a meta_query argument.

    Thread Starter amedic

    (@amedic)

    Hi bcworkz, thank you and Joy for the answer.
    og:image is coming from the Yoast plugin.

    • This reply was modified 6 years ago by amedic.
    Moderator bcworkz

    (@bcworkz)

    Yoast uses this as the meta_key for the og:image value: _yoast_wpseo_opengraph-image
    Use this as the “key” argument in your meta_query code.

    Thread Starter amedic

    (@amedic)

    @bcworkz thank you very much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘meta_query filter posts that has og:image?’ is closed to new replies.