Add metadata to all posts/pages (4 posts)

  1. Robert Accettura
    Posted 5 years ago #

    I want to iterate through every $post (get the $post object), manipulate it, run add_post_meta() to save a change to it for every post/page/attachment (anything with a permalink really) on a blog.

    Is there any script out there already that loops through every asset in a blog?

    The key is every asset and getting the $post so that I could add_post_meta() and work with the contents.

  2. Robert Accettura
    Posted 5 years ago #

    Am I really the only one trying to do this?

  3. telepisodes
    Posted 4 years ago #

    Hi, I don't know where to put this question but I am encountering a problem on my site regarding add_post_meta() function. I don't know if it is just a coincidence or what but the permalink structure of the site always reset to its original setting whenever I execute add_post_meta() programmatically to add new item. Anyone can help me regarding this add_post_meta() and permalink problem.

    Thanks in advance.

  4. Big Bagel
    Posted 4 years ago #

    Regarding the OP if still looking an answer after 5 months...

    Something like this will query for all your published posts:

    $args = array(
        'numberposts' => -1
    $posts_array = get_posts( $args );

    Then you can just make a custom loop to run through each post and do whatever you want with it:

    foreach( $post_array as $post ) {
        /* Code to poke at individual posts */

    Here are the relavent codex pages:


    It would be better to start a new topic since that really doesn't have much to do with the original question asked. For a question like that, I would ask in the How-To and Troubleshooting forum.

Topic Closed

This topic has been closed to new replies.

About this Topic