Skip to content

Add the required 'image' attribute to the Article.#106

Merged
mjangda merged 1 commit intomasterfrom
image-property
Jan 21, 2016
Merged

Add the required 'image' attribute to the Article.#106
mjangda merged 1 commit intomasterfrom
image-property

Conversation

@cfinke
Copy link
Copy Markdown
Contributor

@cfinke cfinke commented Jan 20, 2016

According to https://developers.google.com/structured-data/rich-snippets/articles, the 'image' property is required, so we should do our best to find an image associated with the post.

According to https://developers.google.com/structured-data/rich-snippets/articles, the 'image' property is required, so we should do our best to find an image associated with the post.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can optimize a bit with a direct get_posts lookup here:

$attached_image_ids = get_posts( array(
    'post_parent' => $this->ID,
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'posts_per_page' => 1,
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'fields' => 'ids',
) );

if ( ! empty( $attached_image_ids ) ) {
    $post_thumbnail_id = array_shift( $attached_image_ids );
}

@mjangda
Copy link
Copy Markdown
Contributor

mjangda commented Jan 21, 2016

Related #98 #104 #105

mjangda added a commit that referenced this pull request Jan 21, 2016
Add the required 'image' attribute to the Article.
@mjangda mjangda merged commit b1ac8ad into master Jan 21, 2016
mjangda added a commit that referenced this pull request Jan 22, 2016
get_attached_media fetchs all children even though we only need one.
Just grab the first one instead with a manual get_posts call.

#106 (comment)
@westonruter westonruter deleted the image-property branch February 3, 2018 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants