Home › Forums › Calendar Products › Events Calendar PRO › Remove posts from main loop based on meta field
- This topic has 5 replies, 5 voices, and was last updated 9 years, 11 months ago by
affariproject.
-
AuthorPosts
-
May 13, 2016 at 5:13 pm #1114502
affariproject
ParticipantI need to be able to hide events from both the list and month views based on a meta field’s value. I thought I could simply edit the meta query for the loop using $query->set() with the pre_get_posts filter, but that messes up the order and hiding past events. I’ve looked into recreating the meta query in its entirety with pre_get_posts, but I don’t believe that will work given all the different ways you can filter the posts (upcoming, past, categories, etc.). I’ve also tried figuring out how the “Hide From Event Listings” option works, hoping I could apply the same idea to my meta fields, but my PHP skills aren’t quite advanced enough. Please help me figure this out.
May 16, 2016 at 7:01 am #1114877Geoff B.
MemberGood morning Drew and welcome back!
Thank you for reaching out to us.
I would love to help you with this topic.Just to set expectations, as you might know, the scope of our support is mostly to get our customers started on the right track and to help them in case of issues. We unfortunately do not provide complete support for customization.
With that in mind, the logic of the best approach would probably look a little something like:
Going through the loop, at every turn check the value of the meta field, if it matches then skip loop and go to the next post.If that is still a tad beyond your comfort zone, you might consider hiring one of our recommended customizers to do the customization for you.
Let me know how that goes.
Best regards,
Geoff B.May 16, 2016 at 10:56 am #1115021affariproject
ParticipantYeah, I considered that method. However, that will mess with the number of posts listed on each list view page. If you’re allowing ten posts to show, but six match the meta field, you’ll only see four. Then you might see all ten on the next page if none match the meta. Creates an inconsistent user experience.
May 17, 2016 at 12:05 pm #1115537George
ParticipantHey @affairproject,
Just wanted to chime in here, because we unfortunately cannot much help with your customization goals here. ⚠️ Please read this page before proceeding here in this thread: https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/.
With the above disclaimers in place, and with the fact being that you will have to take the reins on this custom coding and all of the problems/nuances related to it, I did just want to offer some specific advice and touch on a few things you mentioned.
This is not always true as you’ve described it:
If you’re allowing ten posts to show, but six match the meta field, you’ll only see four
If you set the post_per_page and other query parameters properly, and use the meta_query query parameters correctly, then if the settings dictate the returning of “10 post of the event post type that match this meta query”, then 10 posts that match the meta query will be returned; no posts that don’t match the meta query will be returned.
You said earlier in your first post that your “PHP skills aren’t quite advanced enough.” With this in mind I would recommend carefully reading and diligently tinkering with the “Meta Query” information on this page ? https://codex.wordpress.org/Class_Reference/WP_Query
Get creative; use comparison operators like IN, AND, NOT, etc., to stringently specify what the meta queries should be.
With a bit of tinkering you might be more successful than you think. If you need further assistance, check out the professional developers on the list Geoff shared above and considering hiring one for the in-depth coding assistance you may need. There are also site’s like https://codeable.io/ where you can post jobs like this.
Best of luck with your custom development!
GeorgeJune 1, 2016 at 9:35 am #1121224Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘Remove posts from main loop based on meta field’ is closed to new replies.
