Community Forums › Forums › Archived Forums › General Discussion › Reassurance about genesis_get_custom_field?
Tagged: genesis_get_custom_field, WP_query, wp-cron
- This topic has 2 replies, 3 voices, and was last updated 8 years, 8 months ago by coralseait.
-
AuthorPosts
-
July 6, 2015 at 7:40 pm #158594Christopher ArterMember
Hi all,
I'm working on a bit of code for a cron job, and I'm using a WP_Query object to cycle through posts and update the field value of a custom field every 24 hours. The field starts with the value of '30', and every day, it counts down to 0, via this function (hopefully). It will serve as a count-down timer. I know I can use the post date and such, but the custom fields are a bit easier to work with in Gravity Forms & Woo Commerce to 'renew' the post.
My question is.. my cron job isn't working, and I want to rule out the actual function itself. I want to subtract 1 from an integer in the wpcf-engine-days-to-go field, and when I'm using genesis_get_custom_field, I'd just like to make sure there isn't something else I should be doing for it to return the value of the field, or, if there is any problem using a decrementing operator (like --$variable).
function engineDaysToGoCountdown(){ // Set the post args $args = array( 'post_type' => 'engine', 'posts_per_page' => -1, 'post_status' => 'publish' ); //Create enginePosts object $enginePosts = new WP_Query($args); if($enginePosts->have_posts()){ while ( $enginePosts->have_posts()) { $engine->the_post(); // This is the part that I'd like to rule-out $daysLeft = genesis_get_custom_field('wpcf-engine-days-to-go'); /* And this section below too. I'm not sure if the cron job isn't firing, but the database isn't updated. The form creates a post with '30' as the default value of the custom field, and when I run the cron job, it remains 30 in the database */ update_post_meta(the_id(),'wcf-engine-days-to-go',--$daysLeft); } } }
I'd just like a second set of eyes to rule out that the get_genesis_custom_field isn't a problem, and that it's returning the value of the field. Otherwise I'm pretty stumped.
Jack of many trades, master of none.
July 7, 2015 at 5:33 pm #158722Brad DaltonParticipantJuly 9, 2015 at 12:30 am #158876coralseaitMemberAre you using WP Cron or crontab?
A very, very common issue is that many cron schedulers / crontabs (if you are doing them via cli and regular linux crontab instead of wp cron) need newline at the end of the crontab or they won't fire at all and you'll not get any feed back.
Think what you are doing should work, unless your $daysLeft = genesis_get_custom_field('wpcf-engine-days-to-go'); doesn't return int for some reason, so you may wish to do a specific cast to int to make sure.
Probably best to just throw it in a template or function and call the whole thing and echo out to be sure. You'll rule out any strangeness.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.