Jump to content

Recommended Posts

Friends,

 

 

Requirement:

 

I have written a script, which pulls data from various sources on the fly.

So, URL Structure will be like:

 

www.mydomain.com/findprod.php?q=paintball-mask

 

And this findprod.php will use q value and pull data from other sources on the web. I want to make a Post on the Fly and then Write the post Content to Database, so that next time, if i hit the same URL (www.mydomain.com/findprod.php?q=paintball-mask), the Find Product will not be run coz that URL's Data has already been Cached. (Can W3 Cache Plugin Will do this all by its own?)

 

In Other words, Purpose if to Mkae a Post on the Fly and write it to Database as a Cache.

 

 

What i have Done:

 

I have tried to use a fucntion wp_insert_post($ontheflypost) but where shall i put that function? In single.php of my Template or Where?

 

 

global $user_ID;
$new_post = array(
    'post_title' => 'My New Post',
    'post_content' => 'Lorem ipsum dolor sit amet...',
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => $user_ID,
    'post_type' => 'post',
    'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);

 

If i put this snipper in function.php, where do i need to call this Function? Is it in single.php or where?

 

 

 

How can this be done?

Link to comment
https://forums.phpfreaks.com/topic/236324-dynamic-post-in-wordpress/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.