Jump to content

Need some help with my php course


RemiGuru

Recommended Posts

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.

Schermafbeelding 2024-10-22 133440.png

1729597227216(1)(2).jpg

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by RemiGuru
Link to comment
Share on other sites

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 by RemiGuru
Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.