I have a function that pulls in a custom post_type (events) and shows the two upcoming events. It works fine when I pull in the function in a post or page’s sidebar. When I use it on the home page (the one place I need it work at) – it doesn’t work correctly.
$todaysDate = date('Y/m/d');
$event_widget_query = new WP_Query('post_type=events&posts_per_page=2');
It just pulls in the two most recent posts – not the two most recent events. What can I do so that this function works on the home page? Is it a multiple loop issue? I’ve tried rewind_posts and wp_reset_query.
BUT I was wrong!! I cannot fathom why the home page would alter the query code. I see you have tried to do the same thing with ‘query_posts()’ (practically the same as ‘WP_query’). Try to echo out the query string, before and after you create your query – just to make sure that your query is not being modified. (‘echo $query_string’)
Thanks for looking into it. There are two sidebars (sidebar.php and sidebar-home.php). For testing purposes, I have them both calling the function. It only works on posts and pages. If I change it so that home.php calls in the normal sidebar (instead of sidebar-home) – it doesn’t work. If I change single.php so it calls in sidebar-home (instead of the normal sidebar) – it doesn’t work. So, my thought is something must be affecting it inside of home.php. I tried setting it up so the very first thing that home.php does is call in the sidebar. It still doesn’t work.
Home.php is simply running a < ?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> loop.
I might be misunderstanding you, but I tried putting in < ?php echo $query_string;?> before and after the wp_query and nothing gets outputted.