Home › Forums › Calendar Products › Events Calendar PRO › Abstract post types ordering
- This topic has 31 replies, 4 voices, and was last updated 6 years ago by David.
-
AuthorPosts
-
February 28, 2018 at 8:22 am #1465950DavidParticipant
I have Abstract Posts – I cannot get the addition working but that s by the by and something I can live without – the linked Abstract Posts show in the correct order in the back-end – but when displayed using tribe_get_linked_post_types they are coming out in alphabetical order – which is not what I want – how do I change this please?
February 28, 2018 at 9:34 pm #1466752CliffMemberHi, David. What order would you want them in?
tribe_get_linked_post_types() returns an array so you could manipulate it (e.g. reorder/sort it) as you wish, correct?
February 28, 2018 at 11:49 pm #1466819DavidParticipantThe back end provides sorting – via the drag handles – I expected it to come out in the order as defined by how I drag the items into order – else the back-end sorting is not worth having
March 1, 2018 at 2:03 am #1466852DavidParticipantDoes the backend sort save? I cannot seem to sabe the order as defined by the drag handles
March 1, 2018 at 10:06 am #1467477CliffMemberWhere are you using tribe_get_linked_post_types() and please share its output.
That function outputs the linked post types, not the not the posts, if that’s what you’re actually looking for.
March 1, 2018 at 10:16 am #1467493DavidParticipantOk – this is going the same way as my previous question – can you first up answer – should those drag handles do anything – they do not on my install – drag into a new order, hit update – order is not saved
I fully understand that the function outputs the linked post types – below is the code – bastardised from your functions that outputs them – please answer the basic question first – do the drag handles support reordering of the linked post types?
`function get_a_custom_field_key_from_label( $label, $post_type_key, $prepend_underscore = true ) {
$post_type_key = ‘included-element’;
$label = preg_replace( ‘/[-\s]/’, ‘_’, $label );
$label = sprintf( '%s_%s', $post_type_key, $label ); if ( ! empty( $prepend_underscore ) ) { $label = sprintf( '_%s', $label ); } $label = sanitize_key( $label ); return $label; }
function get_custom_field_labels() {
$field_labels = array( 'Phone', 'Website', 'Email Address', ); $field_labels = array_map( 'esc_html', $field_labels ); return $field_labels; }
function get_event_single_custom_fields_output( $post_type_key, $post_id = 0 ) {
$post_id = absint( $post_id ); $output = ''; if ( empty( $post_id ) ) { return $output; } foreach ( get_custom_field_labels() as $custom_field_label ) { $custom_field_key = get_a_custom_field_key_from_label( $custom_field_label, $post_type_key ); $value = get_post_meta( $post_id, $custom_field_key, true ); if ( false === $value || '' === $value ) { continue; } // Build the HTML markup applicable to each field. // By default use esc_html(), but we can't do that for all uses of $value because we already have our desired HTML (with escaped values). if ( 'Website' == $custom_field_label ) { $value = esc_url( $value ); if ( empty( $value ) ) { continue; } $value = sprintf( '<a href="%1$s">%1$s</a>', $value ); } elseif ( 'Email Address' == $custom_field_label ) { $value = antispambot( $value ); if ( empty( $value ) ) { continue; } $email_link = sprintf( 'mailto:%s', $value ); $value = sprintf( '<a href="%s">%s</a>', esc_url( $email_link, array( 'mailto' ) ), esc_html( $value ) ); } else { $value = esc_html( $value ); } $output .= sprintf( '<dt>%s:</dt><dd class="%s-%s">%s</dd>', esc_html( $custom_field_label ), esc_attr($post_type_key), esc_attr( strtolower( $custom_field_label ) ), $value ); } return $output; }
function get_post_type_label( $post_type_key ) {
$label = ‘name’;
$post_type_object = get_post_type_object($post_type_key);
$result = $post_type_object->labels->$label; return $result; }
function get_linked_posts($id, $post_type_key, $output_type) {
$output = ”;
//$output_type = “post-title-only”;
//$output_type = “post-title-content”;
//$output_type = “content-post-title”;
//$output_type = “content-only”;
// IS USED
// echo ‘Called get_linked_posts
‘;//echo “Requested ID: ” . $id;
//$post_type_key = ‘included-element’;
$linked_posts = tribe_get_linked_posts_by_post_type($id, $post_type_key);
// echo ‘
'; // print_r($linked_posts); // echo '
‘;
if ( ! empty( $linked_posts ) ) {
$output .= sprintf(
‘<!–%s
–>
- ‘,
-
%5$s
%6$s - %3$s
-
%3$s
%4$s -
%4$s
%3$s - %3$s
$post_type_key,
get_post_type_label($post_type_key),
$post_type_key
);switch ($output_type) {
case “custom-fields”:
//OUTPUT POST WITH CUSTOM FIELDS AND LINKEDforeach ( $linked_posts as $post ) {
$post_id = $post->ID;$output .= sprintf(
‘‘,
$post_type_key,
esc_attr( $post_id ),
esc_url( get_permalink( $post_id ) ),
esc_attr( get_the_title( $post_id ) ),
esc_html( get_the_title( $post_id ) ),
get_event_single_custom_fields_output( $post_type_key, $post_id )
);
}
break;
case “post-title-only”:
foreach ( $linked_posts as $post ) {
$post_id = $post->ID;$output .= sprintf(
‘‘,
$post_type_key,
esc_attr( $post_id ),
esc_html( get_the_title( $post_id ) )
);
}
break;
case “post-title-content”:
foreach ( $linked_posts as $post ) {
$post_id = $post->ID;$output .= sprintf(
‘‘,
$post_type_key,
esc_attr( $post_id ),
esc_html( get_the_title( $post_id ) ),
esc_html( get_post_field(‘post_content’, $post_id) )
);
}
break;
case “content-post-title”:
foreach ( $linked_posts as $post ) {
$post_id = $post->ID;$output .= sprintf(
‘‘,
$post_type_key,
esc_attr( $post_id ),
esc_html( get_the_title( $post_id ) ),
esc_html( get_post_field(‘post_content’, $post_id) )
);
}
break;
case “content-only”:
foreach ( $linked_posts as $post ) {
$post_id = $post->ID;$output .= sprintf(
‘‘,
$post_type_key,
esc_attr( $post_id ),
esc_html( get_post_field(‘post_content’, $post_id) )
);
}
break;
}$output .= ‘
‘;
}return $output; }
function tec_linked_posts_shortcode($atts = [])
{
// IS USED
// normalize attribute keys, lowercase
$atts = array_change_key_case((array)$atts, CASE_LOWER);// override default attributes with user attributes $passed_atts = shortcode_atts([ 'id' => get_the_ID(), 'post_type_key' => 'included-element', 'output_type' => 'post-title-only', ], $atts, $tag); return get_linked_posts($passed_atts['id'], $passed_atts['post_type_key'], $passed_atts['output_type']);
}
add_shortcode(‘tec_get_linked_posts’, ‘tec_linked_posts_shortcode’);
`March 1, 2018 at 6:30 pm #1467834CliffMemberReordering Organizers in the wp-admin Event edit screen does not work either so I logged this bug.
I marked this thread as Pending Fix, which means it should receive a reply once the applicable fix has been released. I cannot guarantee when it will be fixed as it’s in the development team’s hands now. They need to assign it, code it, test it, and schedule it for release.
I apologize for this issue and appreciate your understanding and patience.
===
Regarding your custom coding, I didn’t see use of tribe_get_linked_post_types()
===
You initially stated the linked posts are always in alphabetical order, but your screenshot at https://theeventscalendar.com/content/uploads/2018/03/f9d91a17c3d9db78.png didn’t appear in alpha-order.
===
Testing with the Organizers linked post type, whatever order they’re added to the event is the order they display on the front-end single event page. I’d assume your linked post type should operate in the same fashion.
March 1, 2018 at 11:58 pm #1467955DavidParticipantSorry you are correct – I am calling tribe_get_linked_posts_by_post_type – this always returns the associated linked posts in alphabetical order as opposed to the sort order on the edit screen – as per my screen shot – it doesn’t matter the entered order – they are always alphabetical
PS I am away as of tomorrow for two weeks – please do not close this ticket down in my absence
March 2, 2018 at 12:00 am #1467957DavidParticipantCompare https://theeventscalendar.com/content/uploads/2018/03/f9d91a17c3d9db78.png – the edit order – with the output order as shown in the attached – the output order IS always alphabetical
March 2, 2018 at 11:31 am #1468605CliffMemberGotcha.
The reason they’re in alpha-order is because of this: https://github.com/moderntribe/the-events-calendar/blob/4.6.11.1/src/Tribe/Linked_Posts.php#L441
I was able to replicate this behavior and logged this bug as well.
Thanks for bringing these 2 bugs to our attention. This thread will stay in Pending Fix status until both are fixed.
March 30, 2018 at 4:44 am #1492587Jaime MarchwinskiKeymasterHi There!
Just wanted to share with you that a new release of our plugins is out, including a fix for this issue 🙂
Find out more about this release —> https://theeventscalendar.com/maintenance-release-week-25-march-2018/
Please update the plugins and let us know if the fix works for your site.
Best,
JaimeMarch 30, 2018 at 12:27 pm #1493108DavidParticipantI am still seeing the same issue – the linked page does not list it as being fixed either
March 30, 2018 at 5:13 pm #1493267CliffMemberHi, David. Sorry for the lack of clarity. The event organizer order not saving after drag-and-drop was the issue fixed.
The other issue — of the Linked Post Types outputting alphabetically — is currently in queue for an upcoming update. We’ll leave this in Pending Fix status until this thread gets updated again.
Thanks for your patience.
April 13, 2018 at 10:13 pm #1507242CliffMemberDavid, just an update that https://theeventscalendar.com/extensions/linked-post-type-instructors/ has been updated to accommodate the soon-to-come The Events Calendar update where Organizers and Venues will display in the wp-admin drag-and-drop order.
This thread will receive another update once that is released.
Have a good weekend.
April 20, 2018 at 9:21 am #1512295VictorKeymasterHi David!
Just wanted to share with you that a new release of our plugins is out, including a fix for this issue 🙂
Please note that you will need to re-save the event for the fix to be effective.
Find out more about this release → https://theeventscalendar.com/maintenance-release-week-15-april-2018/
We appreciate your patience while we worked on this.
Please update the plugins and let us know if the fix works for your site.
Best,
Victor -
-
AuthorPosts
- The topic ‘Abstract post types ordering’ is closed to new replies.