Having Issue on Ordering CPT by Custom Field In Custom WP Query

Question

Having a Custom Post Type loop like this, I am able to return the result on page BUT I am not able to set Order By of display using my own Custom Field.

As you can see here

$topic_number = get_post_custom_values($key = 'topic_order');
echo $topic_number[0];

I am able to get the value of Custom Field and echo it to page but the Order System not doing the job on ordering them. Can you please let me know how to fix this?

$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'topic',
            'field'    => 'slug',
            'terms'    => 'movie',
        ),
    ),
        'post_type' => 'essay',
        'orderby' => 'topic_number',
        'order' => 'DESC',
);

    $loop = new WP_Query( $args ); 
        
    while ( $loop->have_posts() ) : $loop->the_post(); 
$topic_number = get_post_custom_values($key = 'topic_order');

echo $topic_number[0];
        print the_title() ."<br />"; 
        the_excerpt(); 
    endwhile;

0
Behseini 5 days 2021-07-22T12:58:05-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse