WordPress Blog Sticky Post Crontab Curl Tutorial

WordPress Blog Sticky Post Crontab Curl Tutorial

WordPress Blog Sticky Post Crontab Curl Tutorial

As you might have guessed from yesterday’s WordPress Blog Category List Primer Tutorial as shown below, weeeeeee””’rrrrrreeee baaaaaaaccccccckkkk!!!

You might also have guessed that we’d be talking about “WordPress Blog Sticky Posts”, particularly as it mentions it in the title … daaaaaaaaaarrrrrrrrnnnnnnnnn.

But did you know that English sentences shouldn’t start with “but” … maaaaaaaaatttttttttteeeeeee (sorry to break into twaaaaaaaaangggggg).

Seriously, though, WordPress, and probably other blog software products allow you to have “Sticky Posts” that stay in position, and only happen for a WordPress blog’s “landing page” scenario, which, in the case of our WordPress blog (subdomain) would be this landing page. This “intelligence” can be found in a WordPress.org blog’s MySql “wp_options” table and we are very graaaaaaateful today for the great advice regarding this that we got from this useful link … taaaaaaaaaaa!

Using that useful information we cranked up good ‘ol phpMyAdmin (& read more here) …


SELECT wp_options.option_value FROM wp_options WHERE wp_options.option_name='sticky_posts';

… and got the result set …


a:2:{i:0;i:316;i:1;i:7666;}

… which tells me that both 316 and 7666 were “Sticky” at the time of running the query, and, yes, that was true.

So, reckon we are not on a sticky wicket to say that we can now plan our next holiday put the queries as per yesterday’s software_posts.sql and as above to have all the information we need to derive the SQL to update the database every now and then, for variety, to change that second “Sticky Post” to be … to be … to be or not to be … but we digress … to be another WordPress blog posting ID from that list of yesterday (which happened to be a list of WordPress blog posting IDs with category “Software” more than 8 days old).

Do you get what we want to do now? Hopefully yes … and do you get why the 8 days? … that is so a “Recent Post” is not one of the WordPress blog posting IDs chosen, as to allow this to happen, and it did happen, would be a bit dumb.

The SQL to update the MySql database goes something like … where we are making the new “Sticky Post” WordPress blog posting ID 10021 …


UPDATE wp_options SET wp_options.option_value='a:2:{i:0;i:316;i:1;i:10021;}' WHERE wp_options.option_name='sticky_posts';

… so the derivation of 10021 is via a randomly selected category “Software” ID that is not 7666 and is older than 8 days.

Okay we have three pieces of SQL and, ideally, we’d like them to run in the order …

  1. software_posts.sql
  2. SELECT wp_options.option_value FROM wp_options WHERE wp_options.option_name=’sticky_posts';
  3. UPDATE wp_options SET wp_options.option_value=’a:2:{i:0;i:316;i:1;i:10021;}’ WHERE wp_options.option_name=’sticky_posts';

… where 10021 is up for grabs. So let’s put all this into some PHP code you could call sticky_post_list.php and unit test via Linux command line (on the www.rjmprogramming.com.au domain web server) via the use of Curl


curl //www.rjmprogramming.com.au/PHP/sticky_post_list.php

… it works and it creates a new sticky_posts_list_new.php each time, for verification purposes.

So, implementation wise we come back to all those choices of ways and means of making this happen, and we’ve decided on good ‘ol Crontab to do it with the “crontab -l” relevant record entry …


13 */8 * * * curl //www.rjmprogramming.com.au/PHP/sticky_post_list.php

… in other words, we do it every 8th hour and do it at 13 minutes past.

Enjoy today’s tutorial and just remember a change is as good as a holiday …

Hey, Mac … you remember that plan our next holiday … well strike I mean unstrike that … the holiday’s back on!


Previous relevant WordPress Blog Category List Primer Tutorial is shown below.

WordPress Blog Category List Primer Tutorial

WordPress Blog Category List Primer Tutorial

You may well be aware that a WordPress blog, such as the one you are viewing, has a MySql database which is like its signature … well, more than a signature … basically most of its identity, because no matter what styling and theming you apply (and in any case some of the styling and theming ideas get stored in the database as well) the data behind the blog is what makes it what it is.

The WordPress PHP software has a “Fred and Ginger” relationship with its MySql database. Who’s Fred, and who’s Ginger? … leave that for you.

But as with most decent dances you used to be able to tap somebody on the shoulder and ask for a changed arrangement … are you all rolling around on the floor yet? … the older of us have gone to the fridge to get a banana muffin I expect?!

Anyway, to cut a long story short, we are going to separate ourselves from WordPress PHP, and write our own, that sits outside and makes changes to the WordPress blog by adjusting the WordPress blog’s MySql database from this removed position. Okay, if you want to be dramatic … “in a backdoor way”. And what do you need to do this?

  • MySql hostname
  • MySql username
  • MySql password
  • MySql database name

… in order to make a connection to the MySql database from PHP. This word “connection” is absolutely massive in the Information Technology world, because the Information Technology world is increasingly about networking and devices and synchronicity and data and databases and services, but bear in mind (all) this networking was once a secretive and arcane “art”, so things have come along/”a long way” (chortle, chortle). Wonder what the sky would look like if every message we sent via a connection had a unique streaky air-dye colour as it streaked through the atmosphere?

Okay, for the point of today’s mission … we want to end up with a comma delimited list of blog posting ID numbers that all belong to a category of interest (and that are more than 8 days old … thanks).

That last bit probably gives the game away, but, nevertheless we’ll leave it until tomorrow to let you know how this functionality could be of use.

By the way, if you were within WordPress PHP code you could use the “get_posts()” functionality to achieve this as well, I think.

There is, what seems to me, a logical approach to achieving this …

  • create a piece of SQL (an example of which we’ve saved for your perusal you could call software_posts.sql) that will get those ID numbers of a particular category older than 8 days, and for great help here would like to thank this very useful link from WordPress.org support forum (thanks) … in order to achieve this we use the incredible, the marvellous, the witty (you had to be there), the curiously refreshing “phpMyAdmin” … read more here
  • take another piece of PHP that did something like what we want to do today … do you remember tutorial_options.php (from here)? … and plug in the SQL and modify the rest to end up with category_software_list.php … store the results in a file you can see at software_posts_list.php

So we hope to see you back here tomorrow to complete the loop, and in the meantime you might like to review today’s tutorial.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in Database, eLearning, Operating System, Software, Tutorials and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

9 Responses to WordPress Blog Sticky Post Crontab Curl Tutorial

  1. of course like your web-site however you need to take a look at the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very bothersome to inform the truth then again I will certainly come back again.

  2. Would enjoy to always get updated fantastic site ! .

  3. You will discover a number of fascinating time limits in this posting however I don’t know if I see all of them center to heart. There exists some validity nonetheless I’m going to take hold opinion till I check into it additional. Excellent write-up , thanks so we want further! Integrated in FeedBurner as effectively

  4. Thanks for your post. 1 other thing is when you might be disposing your property all on your own, among the difficulties you require to be aware about upfront is just how to deal with home inspection accounts. As a FSBO supplier, the key about successfully shifting your property in addition to saving funds in real estate agent commission rates is understanding. The far more you realize, the smoother your sales effort may possibly be. 1 location in which this is particularly crucial is inspection reports.

  5. argue says:

    You made various fine points there. I did a search on the issue and found nearly all people will have the same opinion with your blog.

  6. understand says:

    Excellent website. Plenty of useful info here. I am sending it to some friends ans also sharing in delicious. And of course, thank you on your sweat!

  7. tranquil says:

    Normally I don’t learn article on blogs, however I wish to say that this write-up very pressured me to try and do so! Your writing taste has been amazed me. Thanks, quite nice post.

  8. Plenty says:

    I enjoy you expressing your point of view.. So content to have found this post.. Love the blog you given.. Appreciate the entry you delivered..

  9. maripoker says:

    magnificent issues altogether, you just received a new reader.
    What might you suggest in regards to your publish that you made some days in the past?

    Any sure?

Leave a Reply to argue Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>