Abstract post types ordering

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.
Viewing 15 posts - 1 through 15 (of 32 total)
  • Author
    Posts
  • #1465950
    David
    Participant

    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?

    #1466752
    Cliff
    Member

    Hi, 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?

    #1466819
    David
    Participant

    The 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

    #1466852
    David
    Participant

    Does the backend sort save? I cannot seem to sabe the order as defined by the drag handles

    #1467477
    Cliff
    Member

    Where 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.

    #1467493
    David
    Participant

    Ok – 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-&gt;labels-&gt;$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

    –>

      ‘,
      $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 LINKED

      foreach ( $linked_posts as $post ) {
      $post_id = $post->ID;

      $output .= sprintf(


    • %5$s

      %6$s
    • ‘,
      $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(

    • %3$s
    • ‘,
      $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(

    • %3$s
      %4$s
    • ‘,
      $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(

    • %4$s
      %3$s
    • ‘,
      $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(

    • %3$s
    • ‘,
      $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' =&gt; get_the_ID(),
                                     'post_type_key' =&gt; 'included-element',
                                     'output_type' =&gt; '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’);
    `

    #1467834
    Cliff
    Member

    Reordering 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.

    #1467955
    David
    Participant

    Sorry 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

    #1467957
    David
    Participant

    Compare 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

    #1468605
    Cliff
    Member

    Gotcha.

    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.

    #1492587

    Hi 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,
    Jaime

    #1493108
    David
    Participant

    I am still seeing the same issue – the linked page does not list it as being fixed either

    #1493267
    Cliff
    Member

    Hi, 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.

    #1507242
    Cliff
    Member

    David, 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.

    #1512295
    Victor
    Keymaster

    Hi 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

Viewing 15 posts - 1 through 15 (of 32 total)
  • The topic ‘Abstract post types ordering’ is closed to new replies.