• Resolved janwill

    (@janwill)


    Hi, sorry for my english. I will do my best.

    I use a custom loop in the functions.php (for a custom shortcode) to show the last posts from a certain category. With your plugin, I will change the category from a post on certain date – thats working fine.

    BUT
    How can I show this special date in my loop in the functions.php?
    I will show the expire date, which I settting with your plugin….

    like

    <?php
        $args = array(
        'post_type'      => 'post',
        'category_name'  => 'dogs',
        'posts_per_page' => 2,
    );
        $query = new WP_Query( $args );
    ?>
    
    <?php if ( $query->have_posts() ) : while ( $query-> have_posts() ) : $query-> the_post(); ?>
    
    <p class="date">
    
    <?php SHOW_EXPIRE_DATE ?></p> 
    
    <?php
        endwhile;
     wp_reset_postdata();
    endif;  
    ?>

    Do you can help me?
    janwill

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter janwill

    (@janwill)

    hmmmm I have found this snippet but this will show not a right date:

    	 <?php echo get_post_meta( get_the_ID(), '_expiration-date', true);  ?>

    For a test I have set the expire date of 21.09.2023 but in the table there are:

    1695331200
    Thread Starter janwill

    (@janwill)

    Ahhhhhh

    <?php echo do_shortcode('[postexpirator type=date]'); ?>

    ?? Thx for help ??

    Plugin Support Riza Maulana Ardiyanto

    (@rizaardiyanto)

    Hi @janwill

    I’m glad your found the solution already.

    For other users that facing the same issue, this is relevant documentation: https://publishpress.com/knowledge-base/shortcodes-to-show-expiration-date/

    Thanks,

    Thread Starter janwill

    (@janwill)

    thxy ??

    But I have another question:

    I′m planning to change the category by a date from your plugin – thats fine and ist working. Now, after change the category, Im planning to show the posts, after a certain time, on another page with another WP_Query-Loop and order (‘meta_key’ => XXX) this posts with the expired date before.

    But I can′t find the expired date in the table AFTER the plugin is change the category…

    DO you know what I mean and do you can help me?

    janwill

    Plugin Author andergmartins

    (@andergmartins)

    @janwill we don’t store the expiration date in the metadata after a post has expired, but you can use an action that is triggered when that happens, before the data is deleted. You could then grab the date and store in a different metadata.

    You can try something like this:

    add_action('publishpressfuture_post_expired', function ($postId) {
        $actionDate = (int)get_post_meta($postId, '_expiration-date', true);
    
        update_post_meta($postId, '_last_expiration_date', $actionDate);
    });
    Thread Starter janwill

    (@janwill)

    Hi, many thx for help. This snippet worked well but I have another quistion for this:

    How can I show the new custom field “_last_expiration_date” in the frontend like the field “_expiration_date”? For “_expiration_date” I use

    [postexpirator type=date]

    But how can I use this shortcode for the new custom fiel to show the date?

    br

    janwill

    Thread Starter janwill

    (@janwill)

    Hi there,

    I could find a solution but I need one change in your code. How can I change your code

    add_action('publishpressfuture_post_expired', function ($postId) {
        $actionDate = (int)get_post_meta($postId, '_expiration-date', true);
    
        update_post_meta($postId, '_last_expiration_date', $actionDate);
    });

    so the value of your custom field _expiration-date is copy to _last_expiration_date AND in another custom field _last_expiration_date_NEW but here with the right date output: d.m.Y H:i?

    I need this for a custom query for the Plugin Search and Filter PRO, so I can filter the posts in the pasts… Do you can help me?

    By the Way is it possible to change your custom field, so that the date is not save in UNIX but in normal date format, or is this to complex?

    janwill

    Plugin Author andergmartins

    (@andergmartins)

    Hi @janwill

    Cool, sure thing. You can try the following code. I left both formats, UNIX time, and your custom format. You can remove or customize according to your need.

    add_action('publishpressfuture_post_expired', function ($postId) {
        $actionDate = (int)get_post_meta($postId, '_expiration-date', true);
    
        update_post_meta($postId, '_last_expiration_date', $actionDate);
        update_post_meta($postId, '_last_expiration_date_NEW', gmdate("d.m.Y H:i", $actionDate));
    });
    
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show date’ is closed to new replies.