{"id":14081,"date":"2015-04-11T05:07:14","date_gmt":"2015-04-10T19:07:14","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=14081"},"modified":"2015-06-28T18:23:30","modified_gmt":"2015-06-28T08:23:30","slug":"wordpress-blog-sticky-post-crontab-curl-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-blog-sticky-post-crontab-curl-tutorial\/","title":{"rendered":"WordPress Blog Sticky Post Crontab Curl Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/CategoryList\/index2.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"WordPress Blog Sticky Post Crontab Curl Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/CategoryList\/Category_Software_Sticky-0017of.jpg\" title=\"WordPress Blog Sticky Post Crontab Curl Tutorial\" \/><\/a><p class=\"wp-caption-text\">WordPress Blog Sticky Post Crontab Curl Tutorial<\/p><\/div>\n<p>As you might have guessed from yesterday&#8217;s <a target=_blank title='WordPress Blog Category List Primer Tutorial' href='#wbclpt'>WordPress Blog Category List Primer Tutorial<\/a> as shown below, weeeeeee&#8221;&#8221;&#8217;rrrrrreeee baaaaaaaccccccckkkk!!!<\/p>\n<p>You might also have guessed that we&#8217;d be talking about &#8220;WordPress Blog Sticky Posts&#8221;, particularly as it mentions it in the title &#8230; daaaaaaaaaarrrrrrrrnnnnnnnnn.<\/p>\n<p>But did you know that English sentences shouldn&#8217;t start with &#8220;but&#8221; &#8230; maaaaaaaaatttttttttteeeeeee (sorry to break into twaaaaaaaaangggggg).<\/p>\n<p>Seriously, though, WordPress, and probably other blog software products allow you to have &#8220;Sticky Posts&#8221; that stay in position, and only happen for a WordPress blog&#8217;s &#8220;landing page&#8221; scenario, which, in the case of our WordPress blog (subdomain) would be this <a target=_blank title='Useful link ... thanks' href='http:\/\/www.rjmprogramming.com.au\/wordpress' title='This WordPress blog landing page'>landing page<\/a>.   This &#8220;intelligence&#8221; can be found in a WordPress.org blog&#8217;s MySql <i>&#8220;wp_options&#8221;<\/i> table and we are very graaaaaaateful today for the great advice regarding this that we got from this <a target=_blank title='Useful link ... thanks' href='http:\/\/wordpress.stackexchange.com\/questions\/21353\/how-to-retrieve-sticky-post-in-raw-sql'>useful link<\/a> &#8230; taaaaaaaaaaa!<\/p>\n<p>Using that useful information we cranked up good &#8216;ol <a target=_blank title='phpMyAdmin landing page' href='http:\/\/www.phpmyadmin.net\/'><i>phpMyAdmin<\/i><\/a> (&amp; read more <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=phpMyAdmin\" title=\"phpMyAdmin at this blog\">here<\/a>) &#8230;<\/p>\n<p><code><br \/>\nSELECT wp_options.option_value FROM wp_options WHERE wp_options.option_name='sticky_posts';<br \/>\n<\/code><\/p>\n<p> &#8230; and got the result set &#8230;<\/p>\n<p><code><br \/>\na:2:{i:0;i:316;i:1;i:7666;}<br \/>\n<\/code><\/p>\n<p> &#8230; which tells me that both <a target=_blank title='WordPress Blog Category List Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=316'>316<\/a> and <a target=_blank title='WordPress Blog Category List Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7666'>7666<\/a> were &#8220;Sticky&#8221; at the time of running the query, and, yes, that was true.<\/p>\n<p>So, reckon we are not on a sticky wicket to say that we can now <strike>plan our next holiday<\/strike> put the queries as per yesterday&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/software_posts.sql_GETME\" title='software_posts.sql'>software_posts.sql<\/a> 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 &#8220;Sticky Post&#8221; to be &#8230; to be &#8230; to be or not to be &#8230; but we digress &#8230; 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 &#8220;Software&#8221; more than 8 days old).<\/p>\n<p>Do you get what we want to do now?   Hopefully yes &#8230; and do you get why the 8 days? &#8230; that is so a &#8220;Recent Post&#8221; 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.<\/p>\n<p>The SQL to update the MySql database goes something like &#8230; where we are making the new &#8220;Sticky Post&#8221; WordPress blog posting ID 10021 &#8230;<\/p>\n<p><code><br \/>\nUPDATE wp_options SET wp_options.option_value='a:2:{i:0;i:316;i:1;i:10021;}' WHERE wp_options.option_name='sticky_posts';<br \/>\n<\/code><\/p>\n<p> &#8230; so the derivation of 10021 is via a randomly selected category &#8220;Software&#8221; ID that is not 7666 and is older than 8 days.<\/p>\n<p>Okay we have three pieces of SQL and, ideally, we&#8217;d like them to run in the order &#8230;<\/p>\n<ol>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/software_posts.sql_GETME\" title='software_posts.sql'>software_posts.sql<\/a><\/li>\n<li>SELECT wp_options.option_value FROM wp_options WHERE wp_options.option_name=&#8217;sticky_posts&#8217;;<\/li>\n<li>UPDATE wp_options SET wp_options.option_value=&#8217;a:2:{i:0;i:316;i:1;i:10021;}&#8217; WHERE wp_options.option_name=&#8217;sticky_posts&#8217;;<\/li>\n<\/ol>\n<p> &#8230; where 10021 is up for grabs.   So let&#8217;s put all this into some PHP code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sticky_post_list.php_GETME\" title='sticky_post_list.php'>sticky_post_list.php<\/a> and unit test via Linux command line (on the www.rjmprogramming.com.au domain web server) via the use of <a target=_blank title='Curl information from computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/curl.htm'>Curl<\/a> &#8230;<\/p>\n<p><code><br \/>\ncurl http:\/\/www.rjmprogramming.com.au\/PHP\/sticky_post_list.php<br \/>\n<\/code><\/p>\n<p> &#8230; it works and it creates a new <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sticky_posts_list_new.php\" title='sticky_posts_list_new.php'>sticky_posts_list_new.php<\/a> each time, for verification purposes.<\/p>\n<p>So, implementation wise we come back to all those choices of ways and means of making this happen, and we&#8217;ve decided on good &#8216;ol Crontab to do it with the &#8220;<a target=_blank title='Crontab information from computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/ucrontab.htm'>crontab<\/a> -l&#8221; relevant record entry &#8230;<\/p>\n<p><code><br \/>\n13 *\/8 * * * curl http:\/\/www.rjmprogramming.com.au\/PHP\/sticky_post_list.php<br \/>\n<\/code><\/p>\n<p> &#8230; in other words, we do it every 8<super>th<\/super> hour and do it at 13 minutes past.<\/p>\n<p>Enjoy today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/CategoryList\/\" title='Click picture'>tutorial<\/a> and just remember a change is as good as a holiday &#8230;<\/p>\n<blockquote><p>\nHey, Mac &#8230; you remember that <strike>plan our next holiday<\/strike> &#8230; well <strike>strike<\/strike> I mean unstrike that &#8230; the holiday&#8217;s back on!\n<\/p><\/blockquote>\n<hr>\n<p id='wbclpt'>Previous relevant <a target=_blank title='WordPress Blog Category List Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=14054'>WordPress Blog Category List Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/CategoryList\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"WordPress Blog Category List Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/CategoryList\/Category_Software_Sticky-00of.jpg\" title=\"WordPress Blog Category List Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">WordPress Blog Category List Primer Tutorial<\/p><\/div>\n<p>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 &#8230; well, more than a signature &#8230; 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.<\/p>\n<p>The WordPress PHP software has a <a target=_blank title='Fred and Ginger' href='http:\/\/www.youtube.com\/watch?v=ydxcHACwX4Y'>&#8220;Fred and Ginger&#8221;<\/a> relationship with its MySql database.  Who&#8217;s Fred, and who&#8217;s Ginger? &#8230; leave that for you.<\/p>\n<p>But as with most decent dances you used to be able to tap somebody on the shoulder and ask for a changed arrangement &#8230; are you all rolling around on the floor yet? &#8230; the older of us have gone to the fridge to get a banana muffin I expect?!<\/p>\n<p>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&#8217;s MySql database from this removed position.  Okay, if you want to be dramatic &#8230; &#8220;in a backdoor way&#8221;.  And what do you need to do this?<\/p>\n<ul>\n<li>MySql hostname<\/li>\n<li>MySql username<\/li>\n<li>MySql password<\/li>\n<li>MySql database name<\/li>\n<\/ul>\n<p> &#8230; in order to make a connection to the MySql database from PHP.  This word &#8220;connection&#8221; 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 &#8220;art&#8221;, so things have come along\/&#8221;a long way&#8221; (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?<\/p>\n<p>Okay, for the point of today&#8217;s mission &#8230; 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 <a target=_blank title='MySql help for the more than 8 days bit ... thanks' href='http:\/\/www.techonthenet.com\/mysql\/functions\/datediff.php'>more than 8 days old<\/a> &#8230; thanks).<\/p>\n<p>That last bit probably gives the game away, but, nevertheless we&#8217;ll leave it until tomorrow to let you know how this functionality could be of use.<\/p>\n<p>By the way, if you were within WordPress PHP code you could use the <a target=_blank title='WordPress get_posts() method' href='https:\/\/codex.wordpress.org\/Template_Tags\/get_posts'><i>&#8220;get_posts()&#8221;<\/i><\/a> functionality to achieve this as well, I think.<\/p>\n<p>There is, what seems to me, a logical approach to achieving this &#8230;<\/p>\n<ul>\n<li>create a piece of SQL (an example of which we&#8217;ve saved for your perusal you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/software_posts.sql_GETME\" title='software_posts.sql'>software_posts.sql<\/a>) 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 <a target=_blank title='Useful link' href='https:\/\/wordpress.org\/support\/topic\/sql-query-to-get-all-posts-from-a-category'>useful link<\/a> from WordPress.org support forum (thanks) &#8230; in order to achieve this we use the incredible, the marvellous, the witty (you had to be there), the curiously refreshing <a target=_blank title='phpMyAdmin landing page' href='http:\/\/www.phpmyadmin.net\/'><i>&#8220;phpMyAdmin&#8221;<\/i><\/a> &#8230; read more <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=phpMyAdmin\" title=\"phpMyAdmin at this blog\">here<\/a><\/li>\n<li>take another piece of PHP that did something like what we want to do today &#8230; do you remember <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/tutorial_options.php_GETME\" title='tutorial_options.php'>tutorial_options.php<\/a> (from <a target=_blank href=\"v chttp:\/\/www.rjmprogramming.com.au\/wordpress\/?s=tutorial_options.php_GETME\" title='tutorial_options.php mentions'>here<\/a>)? &#8230; and plug in the SQL and modify the rest to end up with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/category_software_list.php_GETME\" title='category_software_list.php'>category_software_list.php<\/a> &#8230; store the results in a file you can see at <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/software_posts_list.php\" title='software_posts_list.php'>software_posts_list.php<\/a><\/p>\n<\/ul>\n<p>So we hope to see you back here tomorrow to complete the loop, and in the meantime you might like to review today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/CategoryList\/\" title='Click picture'>tutorial<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d14054' onclick='var dv=document.getElementById(\"d14054\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=SQL\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d14054' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d14081' onclick='var dv=document.getElementById(\"d14081\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=MySql\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d14081' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As you might have guessed from yesterday&#8217;s WordPress Blog Category List Primer Tutorial as shown below, weeeeeee&#8221;&#8221;&#8217;rrrrrreeee baaaaaaaccccccckkkk!!! You might also have guessed that we&#8217;d be talking about &#8220;WordPress Blog Sticky Posts&#8221;, particularly as it mentions it in the title &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/wordpress-blog-sticky-post-crontab-curl-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,29,33,37],"tags":[135,138,151,274,284,355,680,707,827,932,938,972,997,1186,1198,1213,1319,1411,1456],"class_list":["post-14081","post","type-post","status-publish","format-standard","hentry","category-database","category-elearning","category-operating-system","category-software","category-tutorials","tag-batch","tag-batch-programming","tag-blog","tag-crontab","tag-curl","tag-domain","tag-landing-page","tag-linux","tag-mysql","tag-php","tag-phpmyadmin","tag-posting","tag-programming","tag-sql","tag-sticky","tag-subdomain","tag-tutorial","tag-web-server","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/14081"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=14081"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/14081\/revisions"}],"predecessor-version":[{"id":15133,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/14081\/revisions\/15133"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=14081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=14081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=14081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}