只有在标题中有*时才在worpdress中发布图像

时间:2017-03-01 18:29:19

标签: php wordpress

这就是我现在page-name.php

中的内容
<?php

   $args = array(
     'post_type' => 'attachment',
     'numberposts' => -1,
     'post_status' => null,
     'post_parent' => null, // any parent
     'post_mime_type' => 'image'

);  
 $attachments = get_posts($args);
  if ($attachments) {
     $attachment_meta = wp_get_attachment($attachment->ID);
            foreach ($attachments as $post) {
            if ($attachment_meta['caption'] == 'Ceahlau' ){
            setup_postdata($post);
               echo wp_get_attachment_image( $attachment->ID, 'full' );
               the_attachment_link($post->ID, false);

                            }
                }  
}

?>

这就是我在functions.php中所拥有的:

function wp_get_attachment( $attachment_id ) {

    $attachment = get_post( $attachment_id );
    return array(
        'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
        'caption' => $attachment->post_excerpt,
        'description' => $attachment->post_content,
        'href' => get_permalink( $attachment->ID ),
        'src' => $attachment->guid,
        'title' => $attachment->post_title
    );
}



$attachment_meta = wp_get_attachment($attachment->ID);

请告诉我我的功能有什么问题?我想仅在图片中标有"Ceahlau"的情况下发布图片。

0 个答案:

没有答案