Home › Toolset Professional Support › [Resolved] View doesn't display new post created via CRED form
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 |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
This topic contains 8 replies, has 2 voices.
Last updated by Minesh 11 months ago.
Assisted by: Minesh.
Hi,
I have a custom post type "Events". I created a post form so users can create new events. When I was testing the form, I realised it doesn't update any view caches after the new event is created. I tried removing the cache for one of the views and the new post is still not displayed.
I see that the new events are created on the admin page, their page is displayed without a problem.
If I open the event on the admin page and just click update without changing anything, all the views start showing the event.
I found a similar issue here but can't see how it is resolved: https://toolset.com/forums/topic/toolset-forms-adding-and-editing-custom-post-types-not-working/
What is the link to your site?
hidden link
Hello. Thank you for contacting the Toolset support.
I would like to know - are you using block view or classic view to display your view content?
In addition to that - Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/
Hi Minesh,
I provided the debug information from the staging site (I have the same issue there as well).
I am using block view to display the content.
First of all, based on the debug information you shared I find that you are using the outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.
*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/
OR
You can install/update Toolset pluigins using the installer plugin:
-https://toolset.com/faq/how-to-install-and-register-toolset/#automatic-installation-once-you-have-otgs-installer-plugin-installed
Can you please update ALL Toolset plugins to latest version.
Once you update the plugins - what if you try to disable the view cache for your view block?
Hi Minesh,
Thank you for suggesting that. I did the update and tried again but it didn't fix the issue. I've already tried disabling the cache for the views but it doesn't work either. Is there anything else I can try?
Can you please share problem URL where you added your view and what post you created that is not get displayed by the view?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Thank you for sharing all those required links and information and it was bit hard to locate where the issue was but finally happy to say that I found the issue.
Can you please try to create a new event now using the user "yusuf.soysal+halil@gmail.com":
- hidden link
Once you create the event - please check on the "my Camps" page:
- hidden link
Can you please confirm it's working as expected now? If yes:
- The issue was I've adjusted the code you added to your code snippet as given under:
- hidden link
add_action('cred_save_data', 'hvf_add_venue_and_available_dates_to_event',10,2); /* * This function is only intended to work when a logged in camp owner creates a camp */ function hvf_add_venue_and_available_dates_to_event($post_id, $form_data){ // if it is the add camp form if ($form_data['id'] == 23899) { // for some reason, event price is not updated for the event. let's fix that //update_post_meta( $post_id, 'wpcf-event-price', $_POST['wpcf-event-price'] ); $availableDates = $_POST['available-date']; $venueList = $_POST['selectedVenues']; // ADDING EVENT STATUS BY DEFAULT update_post_meta($post_id,'wpcf-event-status','ACTIVE'); // add available dates foreach ($availableDates as $availableDate) { [$startDate, $endDate] = explode(' to ', $availableDate); if( $endDate == null ) { $endDate = $startDate; } $startDateTimestamp = DateTime::createFromFormat('!d/m/Y+', $startDate)->getTimestamp(); $endDateTimestamp = DateTime::createFromFormat('!d/m/Y+', $endDate)->getTimestamp(); $order_item = 1; $args = array( 'post_title' => 'Available Date ' . $availableDate . ' for '. $post_id, 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_type' => 'available-dates', 'meta_input' => array( 'wpcf-start-date' => $startDateTimestamp, 'wpcf-end-date' => $endDateTimestamp, 'toolset-post-sortorder' => $order_item++ ) ); // create the available dates $availableDateId = wp_insert_post( $args ); toolset_connect_posts( 'available-dates', $post_id, $availableDateId ); } // add the venues foreach ($venueList as $venueId ){ toolset_connect_posts( 'venue-event', $venueId, $post_id ); } // associate with the company $args = array( 'post_type' => 'company', 'numberposts' => 1, 'author' => get_current_user_id() ); $companies = get_posts( array( 'post_type' => 'company', 'numberposts' => 1, 'author' => get_current_user_id() ) ); error_log("Companies: " . json_encode($companies)); if( $companies && count($companies) > 0 ){ toolset_connect_posts( 'company-event', $companies[0]->ID, $post_id ); } }
Where:
- I've added the following line of the code to set the Event as "ACTIVE" event by default.
// ADDING EVENT STATUS BY DEFAULT update_post_meta($post_id,'wpcf-event-status','ACTIVE');
I see you set the by default status from custom fields settings to "ACTIVE" But that does not mean that the event status will be automatically added. That is way we are setting the event status as you can see above using update_post_meta() function.
Can you please confirm now it works as expected now.
Oh, that's interesting. I didn't link another snippet to you as I thought it was not related but I have another snippet that's calculating that value: hidden link
Could it be that there is a clash between save_post and cred_save_data actions? I'll add some logs and try to understand that
There should not as cred_save_data action will run once you submit the from from frontend and data is saved to the database.
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
You're welcome to mark resolve this ticket and feel free to open a new ticket with every new question you may have. Glad to help.
Confirming that what you said Minesh is correct. Thank you for your help.
My issue is resolved