Reorder displayed posts with JQuery (title A-Z / last posted)

With WordPress you can utilise a function called wp_localize_script() which allows you to pass in a script, and a variable you would like that script to have access too.

Perhaps by assigning the new query to a variable, and then accessing it within jQuery would help you solve your problem.

The example provided by WordPress explains it pretty clearly:

<?php
  // Register the script
  wp_register_script( 'some_handle', 'path/to/myscript.js' );

  // Localize the script with new data
  $translation_array = array(
       'some_string' => __( 'Some string to translate', 'plugin-domain' ),
       'a_value' => '10');

  wp_localize_script( 'some_handle', 'object_name', $translation_array );

  // Enqueued script with localized data.
  wp_enqueue_script( 'some_handle' );
?>

And then access like so:

<script>
  // alerts 'Some string to translate'
  alert( object_name.some_string);
</script>

So as you can see Javascript is now getting access to the variable translation_array variable by getting hold of the object_name which is tied to the variable $translation_array and is then pulling the value of some_string from the array.

So we could write something along the lines of:

<?php 
    $args = array('order' => 'ASC');
    $get_artists = get_posts($args);

    wp_register_script('artists', 'path/to/artists.js');
    wp_localize_script('artists', 'artist_sort', $get_artists);

    wp_enqueue_script('artists');
?>

And then access the variable within our artists.js script.

[ No Idea if this works, as I haven’t tested it, just purely an example in how you might be able to go about it ]