• Resolved rodrigomarreiro

    (@rodrigomarreiro)


    Hi, I need some help.
    I want to show some content before the publish date of the post and i want to hide on the day of the post.
    How can i get the publish date using php and how can i put that on the shortcode?
    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Arno Welzel

    (@awelzel)

    This question has little to do with Timed Content since what you ask for is just how to use the WordPress core API.

    The post itself has to be queried from the database first and then you can read data like publish date from the post class members.

    See the WordPress Codex about that:

    https://developer.www.ads-software.com/reference/functions/get_post/

    https://developer.www.ads-software.com/reference/classes/wp_post/

    However I don’t see how you could achiev “put that on the shortcode” other than modifying the content of the post which has that shortcode.

    So if you want to extend Timed Content to also use publish dates of other posts as reference instead of a fixed date/time, feel free to extend the shortcode implementation and provide a pull request at https://github.com/arnowelzel/timed-content

    Thread Starter rodrigomarreiro

    (@rodrigomarreiro)

    Thank you, It is working now as I want.

    I just put this simple code in theme files to hide the part of the post:

    `[timed-content-server hide=”<?php echo get_the_date( ‘Y-m-d’ ); ?> 00:01:00 -0600″]

    Plugin Author Arno Welzel

    (@awelzel)

    Using PHP code as inline code of a will usually not work! This is a severe security hole since the post must only contain content and not code!

    That’s the reason why shortcodes exist – a shortcode is content which will be passed as data to a plugin to handle it.

    And if PHP code would work you inside a post (which is normally NOT the case!) you would not need the whole Timed Content plugin – in that case you could just check the dates using PHP itself:

    
    <?php
    // Check if current date is before the post date
    if (date('Y-m-d') < get_the_date('Y-m-d')) {
    ?>
    
    Your content here to be displayed if the current day is before the post date.
    
    <?php
    }
    ?>
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Post Publish date’ is closed to new replies.