Just paste the following code anywhere on WordPress theme files. If you want to test, I recommend pasting it in your functions.php file.
That’s all you have to do. Once executed, this code will insert a new post into WordPress database.
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);
Thanks to Matt Harzewski for this great piece of code!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!WordPress tip: Insert posts programmatically
191 readersIt is a well known fact that your regular visitors don't click on your ads. In order to monetize your blog without annoying your loyal readers, what about displaying ads only when posts are older than 15 days?Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for
1329 readersEach time you define a specific post as being private or password-protected, WordPress automatically add "Private" or "Protected" to your blog post title. If you don't want it, nothing simpler: Just apply this great hack.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!How to remove
67 readersRecently, one site we were working on needed a sidebar that would show the 4 most recent posts on the site. But here’s the catch: they wanted only one post per author. And, each author had to have the role of “author” as opposed to contributor or admin. The site ...
976 readersWordPress 3.0 will allow you to create custom post types, so what about being able to list those custom types on your blog homepage? This very useful piece of code will show you how you can do it.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for
535 readersI like to use Google Analytics, but the boring stuff is that when you switch themes, you'll have to re-insert the code in the new theme. To avoid it, let's use the power of WordPress hook to insert our analytics code without editing theme files.Looking for WordPress hosting? Try WP Web Host. Prices starts at
105 readersWordPress have a feature which saves various copies of your posts in order to allow you to compare revisions or restore an older version of your posts. This is very useful, but it also take a lot of space in your database. Here is a very handy SQL query that will instantly delete all posts
1081 readersThe default output for WordPress’ post_class template tag includes class names for just about every type of page view imaginable: page-parent search-results logged-in author paged Plus just about everything else except for category ID information. It gives some good category-specific class names, but nothing to represent the category ID. For example, including the post_class function like this in your markup: <div <?php
1179 readersIs your blog popular? Do you got receive lots of comments from your readers? If yes, what about displaying the most recent comments in your blog sidebar (or elsewhere) to let your visitors knowing about the discussion?Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!Display
835 readersWordPress login logo looks nice, but sometimes you may want to change it, for example when building a site for a client. In that case, you can use a plugin, or simply take advantage of this cool hack.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for
73 readersOne part of WordPress that I've never been overly impressed with is archives. This isn't so much a WordPress problem as it an archive problem, archives are inherently boring. As a result of this revelation I've spent some time thinking up new ways to present the information. My latest idea was adding charts to represent
2,131
Curious what others are searching for? Below are the most popular search terms over the last 30 days.

