Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to automatically add caption for each picture appears in the name of the image or the alternative text

example Caption add automatic

example

share|improve this question
    
What have you tried so far? –  Andrew Bartel Apr 19 '13 at 20:17
    
webtide.wordpress.com/2009/04/27/… but for alternate text repeat in caption –  Daniela Apr 19 '13 at 21:08
    
Daniela, please explain and show the code you tried to adapt. You can do that updating the Question: edit. How this "automatic" works? Where does the caption text coming from? The screenshot you're showing indicates WordPress pre-3.5. After 3.5 everything changed and became more difficult. –  brasofilo Apr 20 '13 at 3:42

1 Answer 1

To put in a plugin, these solutions came from eskimo and sam.. we simply select all the attachment where the post_excpert is empty and udpate it , put the title of it in description and caption when they are empty

    $s_query = "SELECT ID, post_title FROM `wp_posts` WHERE NOT post_content <=> post_title AND post_type='attachment'";
        $r_result = mysql_query($s_query);

        if($r_result)
        {
            while($row = mysql_fetch_row($r_result)){
                $s_update_query = 'UPDATE `wp_posts` SET post_content="'.$row[1].'", post_excerpt="'.$row[1].'" WHERE ID="'.$row[0].'"';
                mysql_query($s_update_query);
            }
        }

Here another similar query for the same result:

    mysql_select_db(DB_NAME)
or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM wp_posts WHERE post_type= 'attachment' AND post_excerpt= ''";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
$query = "UPDATE wp_posts SET post_excerpt=post_title WHERE post_type='attachment' AND post_excerpt=''";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());

So with these solution we can import(SELECT) many image in wp gallery.Firstly the caption doesn't appear, we need to update (UPDATE)the post to see it in front end.

share|improve this answer
1  
Please explain what your code does and how it works. "these solution came from eskimo and sam.." doesn't count as an explanation. Just a point of note, if you add code to the editor, highlight it, and click on the {} symbol above the code to add it in a code block like in the edit I've done –  Pieter Goosen Jun 4 at 13:44
    
If you're manipulating the WordPress database, you should probably be using the wpdb class. –  Pat J Jun 4 at 14:01
    
yes thank you for your reply i tryied using wpdb class but couldn't figure it out...not an expert, unfortunetly!!if someone can improve these queries, it could be great... –  yuyazz Jun 4 at 14:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.