I use a WordPress blog and I want to show a post without adding anything to database.
What I want to say is:
I generate a post when page loads,and prepend it in homepage.
I’ve searched and found wp_insert_post()
function but it also add to database.
How can i do this with php?
For example:
There is a post array which is generated by a query.How can I insert my post to this array before page loaded?
I want clear my idea.Here’s step by step what i want.
*1)*Im generating an array like that
$arr[‘title] = “my title”,
$arr[‘content’] = “my content”,
*2)*WP sends a query to database and have the posts am i right? And there is an array,to show on the theme and main page?
At this point i want to add my external array(generated in step1 ) to this array(generated by WP via a query)
3) By this way i will be able to add a post without adding it to my database.
You can simply add your virtual post in one of your theme templates as raw HTML.
Alternatively, if you’re feeling adventurous, you could modify the main query results and include your post inside:
The currently accepted answer causes the new post to delete the last post in the loop, because it doesn’t update the post count. Here’s my modified version that also includes:
Here’s the modified code: