• Resolved outhands

    (@outhands)


    Hi,

    Wanted to reverse the order of a shortcode, does anyone know what the default order is within this function? And is there a way to reverse the order inside this function?

    Example now:
    1
    2
    3
    4
    5
    6

    Wanted result
    6
    5
    4
    3
    2
    1

    add_shortcode( 'pers', function ( $atts, $content=NULL ) {
          extract(shortcode_atts(array(
              'position'  => '',
              'content'   => ''
          ), $atts ) );
    
          return esc_attr($position) . ': ' . esc_attr($content);
    });
    
    // Example usage:
    // [pers position="1" content="something here"]

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    There’s nothing in that shortcode to reverse.

    Forget about the code for a minute and explain what you’re trying to accomplish.

    Thread Starter outhands

    (@outhands)

    @sterndata,

    Thank you for your reply, we have build a sort of press release numbered from 1-9 where 9 should be the first one. Thought about it to just save it reversed so it’s set already but if there is a much easier way I would love to hear it from you.

    Moderator keesiemeijer

    (@keesiemeijer)

    Do you use multiple shortcodes with different positions in the content or are you using this in another way?

    I think saving it in reversed order is the easiest way.

    Thread Starter outhands

    (@outhands)

    @keesiemeijer

    Each content has it’s own position, so [pers position="1" content="something here"] and [pers position="2" content="something else here"] agree about saving it reversed is the easiest way to do this.

    Thank you!

    EDIT:
    Solved this issue by saving it reversed into the database query. For this I have used the PHP function: array_reverse();

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Reverse order shortcode’ is closed to new replies.