Sort WP_Query alphabetically from MB Custom Table

Support MB Custom Table Sort WP_Query alphabetically from MB Custom TableResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23792
    rebecmarirebecmari
    Participant

    I would like to make use of ordering for a records database using MB Custom Table. I have created a custom post type for the records and am able to display all data correctly in a php template.

    Using the WordPress, 'orderby' arg does not work. My custom posts are just displaying in the order they were posted.

    $args = array( 
        'post_type' => 'cemetery-records', 
        'posts_per_page'=>20, 
        'orderby'=>'last_name',
        'order'=>'ASC', 
        'paged' => $paged
    );
    $loop = new WP_Query( $args )

    This makes sense to me because it is looking in the WordPress tables, not my custom table. However, I am having trouble finding documentation on how to order them differently based on the data in the custom table. Can you point me in the right direction?

    #23796
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please follow this documentation to know how to use ORDER BY when creating an MYSQL query in the custom table
    https://www.mysqltutorial.org/mysql-order-by/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.