• 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

Expiration date in 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 › Design Tips and Tricks › Expiration date in custom field

This topic is: not resolved

Tagged: custom code, expiration, Prose

  • This topic has 3 replies, 3 voices, and was last updated 8 years, 8 months ago by jamesparkin.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • November 1, 2013 at 5:48 am #70276
    handig
    Participant

    Hi,
    Can't make this code snippet to work with Custom Code of Prose.

    I was looking into setting an expiration date to posts so that they disappear when the date set is expired.

    I was first looking into this plugin, but it seems to use cron jobs instead of custom fields.

    So then I found this code here.

    I'm using Prose with WP 3.7 so I thought I could add it to custom code which I did as follow:

    /*
    This function assumes a custom field named 'expiration' with a human friendly date/time.
    */
     
    function is_post_expired($post_ID = null){
        
        if(!$post_ID) global $post;
        
        $post_ID = $post_ID ? $post_ID : $post->ID;
        
        //Human Friendly Expiration Date
        $expiration = get_post_meta($post_ID, 'expiration', true);
        
        //Adjust server time for your timezone
        date_default_timezone_set('American/New_York');
        
        $expiration_timestamp = strtotime($expiration);
        $time_left = $expiration_timestamp - time();
     
        if($time_left < 0):
            if(expire_post($post_ID))
                return true;
        endif;
            
    }
     
    function expire_post($post_ID){
        
        $args = array(
            'ID' => $post_ID,
            'post_status' => 'draft'
        );
        if(wp_update_post($args))
            return true;
    }

    I then set the custom fields to a date in the past like 10/10/2013 and 10 September 2012 but the posts are still shown.

    What is wrong with the code?

    http://test2.zzpmarketing.com/
    November 1, 2013 at 2:40 pm #70361
    emasai
    Participant

    Can't tell you what is wrong with it, but for php coding questions I usually go to Stackoverflow.com for answers.


    Need Website Customization or a Responsive CSS fix? Contact Me
    Lynne emasai.com

    November 2, 2013 at 3:31 am #70462
    handig
    Participant

    I'm not so php apt. I saw the code snippet and was hoping I could add it like this to the custom code of Prose. So was wondering if somebody could see if that needs some small adaption or isn't a way to implement this?

    May 17, 2014 at 9:14 am #105627
    jamesparkin
    Participant

    Handig

    Have you been able to list yours posts in ascending order according to expiration date? I've been trying to get this code to work. Using Lifestyle Pro.

    $args = array( ‘post_type’ => ‘event’, ‘posts_per_page’ => 15, ‘order’ => ‘ASC’, ‘meta_key’ => ‘_expiration-date’, ‘orderby’ => ‘meta_value’ );
    $eventloop = new WP_Query( $args );
    if ( $eventloop->have_posts() ) : while ( $eventloop->have_posts() ) : $eventloop->the_post();

    //All the Loop Content Goes Here

    endwhile;
    endif;

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ 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

© 2023 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