I'm currently using this plugin http://wordpress.org/extend/plugins/automatic-featured-image-posts/ which creates batches of posts from uploaded images

I'm also using this code here to generate the default content for every new post

add_filter( 'afip_new_post_content', 'diww_default_post_content' );
function diww_default_post_content() {
  $content = "<iframe src=></iframe>";
  return $content;

Now I have a php array of URL's which I want to insert into the src for each post. Is it possible via some loop or sequential manner insert each URL into each post sequentially?


  • URL[0] -> Post[0]
  • URL[1] -> Post[1]
  • URL[2] -> Post[2]

and so on.

  • I am not sure what you want to do. Assign a single image to each post in a loop (until you run out of either posts or images, I assume)? Why do you start talking about images and end by talking about URLS and post? What is the connection?
    – s_ha_dum
    Feb 7, 2013 at 14:54
  • I believe what he's trying to do is to "pull" content from the provided urls - thus the "dynamic content" in the question. But yeah, leading off with the image plugin was sort of confusing..
    – WP Themes
    Feb 7, 2013 at 15:20
  • quick question. How are you getting the urls?
    – WP Themes
    Feb 7, 2013 at 15:22
  • @WPThemes yea that's what I'm trying to do. Basically, each image upload creates automatically a new post associated with that image. In the contents section I want to place an iframe with an URL src. Since I have hundreds of images and I don't want to manually add hundreds of URL's I'm looking for an automatic solution. The URL's I have pulled from google and stored in a php array
    – jc.yin
    Feb 7, 2013 at 15:30
  • And each new post will use only one URL?
    – WP Themes
    Feb 7, 2013 at 15:37

1 Answer 1


Everytime you upload a new image, the afip_new_post_content filter is called which can be used to change the post content before creation - http://wordpress.org/extend/plugins/automatic-featured-image-posts/

Assuming you have a list of URLs stored somewhere - like in the database - you need a function that would get a url from this list, then delete the url you used from that list so it doesn't get used again.

function get_one_url(){
     * your urls would be stored somewhere I suppose. Everytime you get a url,
     * the number of URLs would decrease by one.

    //this is just a sample. you could probably build this using a database call.
    $list_of_urls = array(

    //get the first url off the list and save it to the variable $url
    $url = array_shift( $list_of_urls );

    //save new list to database. This is just a sample.
    save_my_list( $list_of_urls );

    return $url;

add_filter( 'afip_new_post_content', 'diww_default_post_content' );
function diww_default_post_content() {
    $url = get_one_url();
    $content = "<iframe src={$url}></iframe>";
    return $content;

  • that code looks pretty much like what I need! I'm going to have a go at it now, and report back asap! Thanks
    – jc.yin
    Feb 7, 2013 at 16:07
  • omg, thank you it works your code. Thanks so much for the help! :) you rock
    – jc.yin
    Feb 7, 2013 at 16:26
  • you're welcome.. glad it worked for you :)
    – WP Themes
    Feb 7, 2013 at 16:28
  • If I could up vote your answer I would but I don't have enough points yet :p
    – jc.yin
    Feb 7, 2013 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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