Skip Navigation

[Resolved] Need to hide posts when the check box is selected.

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by andrewD-10 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1560845

Reference: [Hide posts if their checkbox is checked in a front end view & filter] support ticket Link: https://toolset.com/forums/topic/hide-posts-if-their-checkbox-is-checked-in-a-front-end-view-filter/

I tried the above code and did not work. I should have tried it sooner before the ticket closed but never had time until now. Also, I am bummed that it doesn't work.

What I have is a check box custom field where we select the checkbox when this (cpt) post does not have any projects in it. I have about 100 posts that have this check box selected (checked).

What I want to do is on the front end of a view to show all the posts that do not have the check box selected. As in all the posts showing in the view do have projects in them.

The problem is right now when I have the checkbox filter it shows me only the posts that are checked and do not have projects in side the post. So essentially I want to make the filter do the opposite by hiding these posts with the checkbox selected.

Current: When filter active and posts with the checkbox checked, only showing posts with the checkbox selected.
Desired: When filter active and posts with the checkbox checked, hide posts with the checkbox selected from the view.

#1561075

Hello,

It is a custom codes problem, please provide a test site with the same problem, fill below private message box with login details and FTP access, also point out:
- problem page URL
- view URL
- where I can edit your PHP codes,

I need a live website to test and debug it, thanks

#1562125

Thanks for the details, I have done below modifications in your website:
Dashboard-> Toolset-> Settings-> Custom codes
Add an item "hide-post", with below codes:

add_filter('wpv_filter_query', function($query, $setting, $view_id){
    if($view_id == 34149 && isset($_GET['wpv-wpcf-agency-never-posts-projects']) && $_GET['wpv-wpcf-agency-never-posts-projects'] == 'NEVER Post Projects' && isset($query['meta_query'])){
        foreach($query['meta_query'] as $k => $v){
            if(isset($v['key']) && $v['key'] == 'Wpcf-Agency-Never-Posts-Projects'){
                $query['meta_query'][$k]['key'] = 'wpcf-agency-never-posts-projects';
                $query['meta_query'][$k]['compare'] = 'NOT EXISTS';
            }
        }
    }
    return $query;
}, 10, 3);

Please test again, check if it is fixed, thanks

#1565835

My issue is resolved now. Thank you!

Thank you Luo for helping me get this resolved!

#1566017
Screen Shot 2020-03-27 at 11.36.45 AM.png
Screen Shot 2020-03-27 at 11.36.16 AM.png

Hi Luo,

I went ahead and implemented this on my live site, but unfortunately it is having issues. Only very few posts now show with the code.

In the two screenshots below it shows the pagination between the live (smaller) and staging site (larger).

Im trying to figure out why, but so far I have no luck.

#1566137

I just sorted the table by post title and it gave me alittle more results, now up to page 16. But It should be higher, so there is still an issue somewhere.

Additionally, I notice that when the filter is on and I look for posts there are some posts that do not show even though the checkbox (agency never post projects) is not checked, so It should have shown.

#1566139

Link: hidden link

Link: hidden link

The 2 videos above will really help out what might be happening.

#1567559

I have treid again in your staging site:
hidden link
After login the website, I don't see any view or dashboard, I see only below message:
This content is for members only.

Please check it, make sure the staging website is ready for debug.

Since it is a custom PHP codes problem, I need to test and debug it in a live website, thanks

#1569925

Hi Lou,
I was able to filter the view through a query where the Agencies that don't post projects have a 1 in the database. So the query filter I set to a constant and set it equal to 0. This way only the agencies that do post projects will show.

At this time I don't need the front end filter. But if I need something like this in the future I will try the code you provided above.

Thank you for all the support you provided!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.