• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Reassurance about genesis_get_custom_field?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Reassurance about genesis_get_custom_field?

This topic is: not resolved

Tagged: genesis_get_custom_field, WP_query, wp-cron

  • This topic has 2 replies, 3 voices, and was last updated 11 years, 1 month ago by coralseait.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • July 6, 2015 at 7:40 pm #158594
    Christopher Arter
    Member

    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 #158722
    Brad Dalton
    Participant

    This is how i recommend you print the value of a custom field.

    Try

    get_the_ID()

    or

    $post->ID

    Tutorials for StudioPress Themes.

    July 9, 2015 at 12:30 am #158876
    coralseait
    Member

    Are 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.


    Coral Sea IT

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble