RemiGuru Posted October 22 Share Posted October 22 Hi guys. I hope there is someone out there who can help me with my problem i am running into. I am doing a course right now for wordpress developer. But something is going wrong. As you can see in the image. One i had to screenshot with my phone as the video went black as soon i tried to snap it. In here i have the files: https://github.com/Smoshed/phpcoursetraining (if you wondering what course i am doing. its right here: https://www.udemy.com/share/1013mw3@iuLQ5TWH0c9kLuHMg67Cu-gg9d03omPG8xeO4-xPbyPzE-wessX2klyBx4ZdgWpenw==/) ---- Ok, now i will explain what is going wrong. and i feel the error lays in the front-page.php. I have been looking trough it. but i could not find the error myself. There error could be in one of the files: - front-page.php - archive-event.php - single-event.php or maybe even in functions.php --- I hope someone can help me with this issue i am having. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 22 Share Posted October 22 4 hours ago, RemiGuru said: Ok, now i will explain what is going wrong. And where is that? I'm guessing that you're expecting to see those two events in your version of the code but, according to that one screenshot, are not. Without seeing code or data, I'm also guessing it's going to be one or more of: - You don't have the data for the events - The data for the events is present but incorrect - The query to retrieve the data is incorrect - The query is correct but the code to display the data is incorrect Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 22 Share Posted October 22 Based on your github, I would agree that is the location of where things may or may not be working. <h2 class="headline headline--small-plus t-center">Upcoming Events</h2> <?php $today = date('Ymd'); $homepageEvents = new WP_Query(array( 'posts_per_page' => 2, 'post_type' => 'event', 'meta_key' => 'event_date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'event_date', 'compare' => '>=', 'value' => $today, 'type' => 'numeric' ) ) )); while($homepageEvents->have_posts()) { So notice what is actually happening in this code. There is a comparison being done '>=' to event_date meta data. So, what this indicates, is that even if you have rows in the table, and there is a meta key by that name, the values must be in the future, or there will be no results returned. Assuming you copied all this code from some source, the data still must qualify, or the query can return an empty set, which is not an error, and would explain a blank page, since the while loop will not be entered since $homepageEvents->have_posts() will return false. Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 22 Share Posted October 22 (edited) Forgot about how WP metadata works - ignore me. Edited October 22 by maxxd Quote Link to comment Share on other sites More sharing options...
RemiGuru Posted October 23 Author Share Posted October 23 First of all bless you guys for helping me out on this one! @gizmola i thought myself the error was laying in there. but i wasn't sure. Thank you so much for digging trough it. To answer some questions here. - I wrote all the codes myself with the help of the course. Quote Link to comment Share on other sites More sharing options...
RemiGuru Posted October 23 Author Share Posted October 23 (edited) 19 hours ago, requinix said: And where is that? look at the pictures? Sorry if i am not clear enough. As i cant really figure out myself where exactly the problems lays. Edited October 23 by RemiGuru Quote Link to comment Share on other sites More sharing options...
RemiGuru Posted October 23 Author Share Posted October 23 (edited) 15 hours ago, gizmola said: Based on your github, I would agree that is the location of where things may or may not be working. <h2 class="headline headline--small-plus t-center">Upcoming Events</h2> <?php $today = date('Ymd'); $homepageEvents = new WP_Query(array( 'posts_per_page' => 2, 'post_type' => 'event', 'meta_key' => 'event_date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'event_date', 'compare' => '>=', 'value' => $today, 'type' => 'numeric' ) ) )); while($homepageEvents->have_posts()) { So notice what is actually happening in this code. There is a comparison being done '>=' to event_date meta data. So, what this indicates, is that even if you have rows in the table, and there is a meta key by that name, the values must be in the future, or there will be no results returned. Assuming you copied all this code from some source, the data still must qualify, or the query can return an empty set, which is not an error, and would explain a blank page, since the while loop will not be entered since $homepageEvents->have_posts() will return false. Ok. I read through your response carefully. And understand that the value cannot be $today. Is this correct? If this is correct, how can I then use today's date? Since these need to automatically return when an event is created in WordPress. Edited October 23 by RemiGuru Quote Link to comment Share on other sites More sharing options...
RemiGuru Posted October 23 Author Share Posted October 23 I updated my github: https://github.com/Smoshed/WPphpCourse I did some classes back to see. if i can find the issue again. Because it seems there is a lot more going on. Quote Link to comment Share on other sites More sharing options...
gizmola Posted Monday at 07:28 PM Share Posted Monday at 07:28 PM What I am saying is that this might be a data problem not a code problem. It is designed to show you events in the future. If the date of the events is not in the future, those rows will not be returned. That is not an error or a bug, that is working as expected. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.