0

so I'm developing a WordPress website, I'm using "Advanced Custom Fields" plugin. I added two fields groups one by the name event_date with a type date and the second one by the name related_service with a type relationship, the related_service it shows in the event type post to relate a service to an event. so in the page single service I want to show the upcoming events that are related to the service. I used WP_Query to show posts from post_type events. i did a piece of code but something is wrong and and don't know what I did wrong. this code is showing all the events that are coming in the future but not related to the service, so the first array in the meta_query seems to work perfectly buy the second one I don't know what's wrong with it . the code :

<?php
                                $UpcomingRealeatedEvents = new WP_Query(array(
                                    'post_type' => 'event',
                                    'posts_per_page' => 2,
                                    'meta_key' => 'event_date',
                                    'orderby' => 'meta_value_num',
                                    'order' => 'ASC',
                                    'meta_query' => array(
                                        array(
                                            'relation' => 'AND',
                                            'key' => 'event_date',
                                            'compare' => '>=',
                                            'value' => date('Ymd'),
                                            'type' => 'numeric',
                                        ),
                                        array(
                                            'key' => 'related_service',
                                            'compare' => 'LIKE',
                                            'value ' => '"'.get_the_ID().'"'
                                        )
                                    )
                                ));
                                while ($UpcomingRealeatedEvents->have_posts()) {
                                    $UpcomingRealeatedEvents->the_post();

                                ?>
                                    <div class="item-download">
                                        <a href="<?php the_permalink(); ?>" target="_blank"><i class="fa fa-calendar" aria-hidden="true"></i><?php the_title(); ?></a>
                                    </div>
                                <?php } ?>

I tried every thing I can.

2
  • The 'relation' => 'AND' should be just under the meta_query line and not inside the array. Commented Jan 21, 2023 at 14:41
  • idk know how did she got there, i put it under meta_query still not working Commented Jan 21, 2023 at 14:51

1 Answer 1

0

I found the problem guys and it was so stupid hahahahha this think is just there is a space near to 'value' in the meta_query

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.