WordPress.org

Ready to get started?Download WordPress

Forums

Add metadata to all posts/pages (4 posts)

  1. Robert Accettura
    Member
    Posted 3 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
    Member
    Posted 3 years ago #

    Am I really the only one trying to do this?

  3. telepisodes
    Member
    Posted 2 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
    Member
    Posted 2 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:

    http://codex.wordpress.org/Template_Tags/get_posts
    http://codex.wordpress.org/Class_Reference/WP_Query

    @telepisodes:
    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