• Kyle

    (@kylebravotangoca)


    Lazy blocks is ignoring order and orderby parameters for WP_query and get_posts in lazy blocks. All 5 of these queries return the posts in the same order:

    $args = array(
    'numberposts' => -1,
    'orderby' => 'Title',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'Title',
    'order' => 'DESC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'ID',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);


    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'title',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);


    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);
Viewing 1 replies (of 1 total)
  • Thread Starter Kyle

    (@kylebravotangoca)

    Hello, is there any updates on the query sorting issue, it is still present? We are currently using a hacky usort workaround so we could launch the site. Here is some additional information if it helps:

    How to replicate
    1. Install WP
    2. Use the default Twenty Twenty-Two, Twenty Twenty-Three, or Twenty Twenty-Four theme.
    3. Add Posts for testing
    4. Add Lazy block
    5. Add Lazy block template to theme folder /twentytwentyfour/blocks/lazyblock-test/block.php
    6. Query posts with get_posts() or WP_Query()

    I have verified that there is not any hooks like pre_get_posts, and all queries are properly reset in Twenty Twenty-Two, Twenty Twenty-Three, or Twenty Twenty-Four themes that could be causing issues.

    Here is some additional queries that are being ignored.

    $args = array(
    'numberposts' => -1,
    'orderby' => 'title',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'title',
    'order' => 'DESC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'ID',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'author',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'type',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'numberposts' => -1,
    'orderby' => 'parent',
    'order' => 'ASC',
    );
    $custom_posts = get_posts($args);
    var_dump($custom_posts);

    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'title',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);


    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);

    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'name',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);

    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'modified',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);

    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'menu_order',
    'order' => 'ASC',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);

    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'rand',
    );
    $custom_posts = new WP_Query($args);
    var_dump($custom_posts);
Viewing 1 replies (of 1 total)
  • The topic ‘Queries within blocks Ignoring order and orderby parameters’ is closed to new replies.