Hello,
I am very sorry, but at the moment this is not possible by the API. I have to change the way we are saving the date. We are saving the date as string and we need it as timestamp to do the query. I have added a ticket for that and will change this in the next beta.
Here is the Issue on Github on that topic:
https://github.com/awsmug/torro-forms/issues/298
At the moment there is only the possibility to use the function get_posts to get all from post_type “torro_form” and to check the dates manually.
Greetings,
Sven
-
This reply was modified 9 years, 8 months ago by
Sven Wagener.
I have written you the function for the actual version of Torro Forms:
function get_active_forms_that_are_not_expired() {
global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'torro_form'" );
$active_forms = array();
foreach( $results AS $result ) {
$start_date = get_post_meta( $result->ID, 'start_date', true );
$end_date = get_post_meta( $result->ID, 'end_date', true );
if( empty( $start_date ) && empty( $end_date ) ) {
continue;
}
if( strtotime( $start_date ) > time() ) {
continue;
}
if( strtotime( $end_date ) < time() ) {
continue;
}
$active_forms[] = $result;
}
return $active_forms;
}
I hope that helps you! 🙂
Hi Sven Wagener
Thank you for your time.
I will keep an eye on the github repo. And in the meantime I wil use your code as you suggesting.
Sorry to open This Thread again. I am carry on from the last question.
I am trying to make a shortcode to show if there is a survey and if you are part of the people selected in that specific survey.
But I want to get all participants of these open form. In the other plugin you did something like this :
<?php
$results = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'torro_form'" );
$form_id = $result->ID;
foreach( $results AS $result ) {
$sql = $wpdb->prepare ( "SELECT user_id FROM participats_table WHERE survey_id = %s", $form_id );
$user_ids = $wpdb->get_col( $sql );
$current_user = wp_get_current_user();
if ( in_array($current_user->ID, $user_ids) && count( $user_ids ) > 0 ) {
//Rest of my code
}
}
?>
1.) What is the name of the participants table?
2.) Does it have user id’s ?
Regards
-
This reply was modified 9 years, 7 months ago by
acedesign123. Reason: Specify the question
Sorry, I answered my Own Question
Here is the answer.
<?php
function scop_due_date_function($atts) {
global $wpdb;
$goto = get_page_link(522);
$results = $wpdb->get_results( " SELECT * FROM $wpdb->posts WHERE post_type = 'torro_form' AND post_status = 'publish' ORDER BY ID DESC LIMIT 1 " );
//https://github.com/awsmug/torro-forms/blob/3da63aa1716192073c94e95dda467a0b3219ce9a/torro-forms.php#L436
foreach( $results AS $result ) {
$form_id = $result->ID;
$current_user = wp_get_current_user();
$sql = $wpdb->prepare ( "SELECT user_id FROM $wpdb->torro_participants WHERE form_id = %s", $form_id );
$participants = $wpdb->get_col( $sql );
if ( is_array( $participants ) && count( $participants ) > 0 && in_array($current_user->ID, $participants) ) {
$a = shortcode_atts( array(
'name' => $result->post_title,
'date' => get_post_meta( $result->ID, 'end_date', true ),
), $atts );
return "<p> <a href='{$goto}'> {$a['name']} </a>" . "<span style='float:right;'>{$a['date']}</span> </p>";
}
elseif (!in_array($current_user->ID, $participants)) {
return "<p> There are no Scop's currently running. </p>";
}
else {
return "<p> Something went wrong. </p>";
}
}
}
add_shortcode('scopdue', 'scop_due_date_function');
?>
I tried to use
$participants = torro()->participants()->query( array(
'number' => -1,
'form_id' => $form_id,
) );
But I was getting Protected
Array
(
[0] => Torro_Participant Object
(
[user_id:protected] => 3
[user:protected] => WP_User Object