Query posts from URL String
-
Hello,
I want to query posts based on post date & category. The code I am using to display results
<?php query_posts( 'category-name=Events&month='.$month.'&day='.$day ); ?> <?php while (have_posts()) : the_post(); ?> <ul> <li><a href="<? the_permalink(); ?>"><? the_title(); ?></a> <small><?php the_date('Y-m-d'); ?></small> </li> </ul> <?php endwhile;?>
I would like to pass the values of month and day from a url string as follows:
<a href="<? bloginfo('home'); ?>/event-results?month=<?php echo $calendar->month() ?>&day=<? echo $number; ?>&year=<?php echo $calendar->year ?>"><?php echo $number ?>
The way I have this setup, is as follows:
1) I created a custom template that contains the above query – I assigned this template to a page named: Event Results2) On another custom template, I am generating a calendar ( see live page: https://www.htmlupdates.com/demo/chuck/event-calendar/ ) Each date generates a unique url ( day updates from loop – $number.
3) When visitor clicks the link a listing of all posts having the publish date equal to the date selected
Currently – the event-results page returns an error and is not accepting the sent string. In-fact, it seems that when visiting event-results – it is not even using the set page template ( which would make it impossible to display the query in event-results.php custom template ).
This url works:
https://www.htmlupdates.com/demo/chuck/event-results/?month=October&day=25&year=2011
( see explanation https://www.screencast.com/t/EDapgLAs1 )This url works:
https://www.htmlupdates.com/demo/chuck/event-results/
( no url string – link directly to event-results page )This url DO NOT work:
https://www.htmlupdates.com/demo/chuck/event-results?month=October&day=27&year=2011
( Note: Although there is no post set for that day, there should still show the echo I have on the custom template to display url string data )Any help is very much appreciated
- The topic ‘Query posts from URL String’ is closed to new replies.