Skip Navigation

[Resolved] Some custom posts NOT appearing on dashboard custom posts list

This support ticket is created 5 years, 4 months 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 4 replies, has 2 voices.

Last updated by PaulS4783 5 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1322579
dashboard.png

On the WordPress dashboard, under a custom post type "Events" it should (of course) list all of the posts of that type that have been created to date.

HOWEVER, on my site not all are listed.
The post type has custom fields "start date" and "end date".
Strangely, all posts with an end date PRIOR to today have disappeared from the list.
YET they are obviously still in the database.
In fact, the expired event posts still appear under the custom view to display them.
hidden link

See the attached image which only shows the one event on the list.
fyi I am using the most current version of all ToolSet and WPML plugins.

#1322789

Hello,

The problem you mentioned above is abnormal, please check these:
1) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2019, and test again

2) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

3) If the problem still persists, please provide database dump file(ZIP file) of your website, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1324241

OK. Progress made!
So I managed to isolate the cause to a custom function that was in my child theme'

//Return events which have not expired i.e. with END dates greater than NOW:
add_filter( 'pre_get_posts', 'hide_expired_events' );
function hide_expired_events( $query ) {
    if ( is_post_type_archive('event') && $query->is_main_query() ) { // if it is event archive page
		$meta_query = $query->get('meta_query');
		if(!is_array($meta_query)){ // by default
			$meta_query = array();
		}
        $meta_query[] = array(
                'key'     => 'wpcf-end-date', 
                'value'   => current_time('timestamp'),
                'compare' => '>=',
        );
		$query->set('meta_query', $meta_query);
		return;
    }
}

We NEED this filter for the front end.
HOWEVER, it appears that the filter is erroneously applying itself to the back end dashboard as well, in the listing of custom posts.

SO, I just need to figure out how to ONLY apply this filter to the front end.
Any suggestions?

#1324247

You can check if it is not in admin side, then apply your custom codes, for example:
modify this line from:

if ( is_post_type_archive('event') && $query->is_main_query() ) { // if it is event archive page

To:

if ( !is_admin() && is_post_type_archive('event') && $query->is_main_query() ) { // if it is event archive page

More help:
https://codex.wordpress.org/Function_Reference/is_admin
This Conditional Tag checks if the Dashboard or the administration panel is attempting to be displayed.

#1324273

Thank you so much! Very helpful.

Issue resolved.