Suport » Probleme și soluții » postare imagine doar daca are „Ceahlau” in caption

  • Salut,
    Am nevoie de o functie care sa posteze imaginile doar daca au „Ceahlau” in caption sau descriere:

    <?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);
    
                                }
                    }  
    }
    
    ?>

    Asta am in page-name.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);

    si asta am in function.php

  • Subiectul ‘postare imagine doar daca are „Ceahlau” in caption’ este închis pentru noi răspunsuri.