This support ticket is created Il y a 2 années et 3 mois. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Tell us what you are trying to do? On this link (hidden link) I have either on the drop down or tour dates tab some dates I like to order...
For one part I use this:
/* function get_featured_dates with shortcode show_featured_dates to show the dates on a single tour */
function get_my_featured_dates() {
global $post;
$str = '';
$origin_id = $post->ID;
$relationship_slug = 'tourid';
$results = toolset_get_related_posts (
// get posts related to this one
$origin_id, // get posts connected to this one
$relationship_slug, // in this relationship
array(
'query_by_role' => 'parent', // origin post role
'role_to_return' => 'child', // role of posts to return
'return' => 'post_id', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'offset' => 0, // starting from
'orderby' => 'wpcf-tour-date-field',
'order' => 'ASC',
'args' => null // for adding meta queries etc.
)
);
$alltourdates = count($results);
$today = strtotime('today midnight');
$mycounter = 0;
while ($mycounter < $alltourdates)
{
$tour_date_field = get_post_meta( $results[$mycounter], 'wpcf-tour-date-field', true);
if($today < $tour_date_field) {
$myresults = date( 'd. F Y', $tour_date_field);
$str .= $myresults.'<br>';
}
$mycounter++;
}
return $str;
}
add_shortcode( 'show_my_featured_dates', 'get_my_featured_dates' );
I am not sure if this orderby is working or not. Or how I need to use it.
Thank you for contacting us and I'd be happy to assist.
In my tests, I was able to order the results correctly based on the "tour-date-field", by using slightly updated code:
/* function get_featured_dates with shortcode show_featured_dates to show the dates on a single tour */
function get_my_featured_dates() {
global $post;
$str = '';
$origin_id = $post->ID;
$relationship_slug = 'tourid';
$results = toolset_get_related_posts (
// get posts related to this one
$origin_id, // get posts connected to this one
$relationship_slug, // in this relationship
array(
'query_by_role' => 'parent', // origin post role
'role_to_return' => 'child', // role of posts to return
'return' => 'post_id', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'offset' => 0, // starting from
'orderby' => 'meta_value_num',
'order' => 'ASC',
'args' => array(
'meta_key' => 'wpcf-tour-date-field',
),
)
);
$alltourdates = count($results);
$today = strtotime('today midnight');
$mycounter = 0;
while ($mycounter < $alltourdates)
{
$tour_date_field = get_post_meta( $results[$mycounter], 'wpcf-tour-date-field', true);
if($today < $tour_date_field) {
$myresults = date( 'd. F Y', $tour_date_field);
$str .= $myresults.'<br>';
}
$mycounter++;
}
return $str;
}
add_shortcode( 'show_my_featured_dates', 'get_my_featured_dates' );