• Resolved onethousandseas

    (@onethousandseas)


    I’m trying to write a search.php template that, when returning both pages and posts, would only return the date if the post_type was a post. Otherwise it would do nothing.

    I’ve tried using post_class or quest_posts but I couldn’t very far with them. Anyone have any ideas on how I can make this work?

    TY.

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php if($post->post_type == 'post') :
    echo the_date();
    endif;?>
    Thread Starter onethousandseas

    (@onethousandseas)

    Thanks for replying to my question esmi ??

    I inserted the code into my page and here’s what I have:

    https://onethousandseas.org/testblog?s=lorem

    It works well for the first few posts, but I’m not sure why it wouldn’t show up for the next 2 that are posts but not pages (only the last article is a page which contains “lorem”) which means there should be dates on the rest as well.

    Here is the code I have for the page right now:

    https://wordpress.pastebin.ca/1506364

    I’m not seeing any dates on that page of search results…

    Thread Starter onethousandseas

    (@onethousandseas)

    Got it! Customized it a little:

    <?php
    if($post->post_type == 'post') {
    echo the_time('Y');
    echo the_time('M');
    echo the_time('j');
    echo the_time('H:i');
    }
    else {print "Page";}
    ?>

    But does anyone know how I can fit new lines in there? I’d like it to be something like this:

    <?php
    if($post->post_type == 'post') {
    echo the_time('Y'); [NEWLINE]
    echo the_time('M'); [NEWLINE]
    echo the_time('j'); [NEWLINE]
    echo the_time('H:i');
    }
    else {print "Page";}
    ?>
    Thread Starter onethousandseas

    (@onethousandseas)

    Found my answer, here’s how it looks, marking it resolved ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to return dates only on posts not pages in search results?’ is closed to new replies.