Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 21, 2016
Merged

Conversation

cfinke
Copy link
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.
$post_thumbnail_id = get_post_thumbnail_id( $this->ID );
}
else {
$attached_media = get_attached_media( 'image', $this->ID );
Copy link
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
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