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.
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/
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?
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.
Thank you so much! Very helpful.
Issue resolved.