php – Why is this code not working?

Question

I’m trying to create a code to sort posts by number of views or alphabetically.
I haven’t figured out what the problem is yet

 $orderby = isset( $_GET['m_orderby'] ) ? $_GET['m_orderby'] : 'latest';
   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   $query = (array(
  'post_type'    => 'post',
'post_status'  => 'publish',
'paged'        => $paged
));
$args = array();
$query = wp_parse_args( $args, $query );
if ( $orderby ) {
switch ( $orderby ) {
    case 'latest':
        $query['orderby']  = 'meta_value_num';
        $query['meta_key'] = 'dt_views_count';
        $query['order'] = 'DESC';
        break;
    }
   }
  ?>

 <div class="c-nav-tabs">
    <span> <?php esc_html_e('Order by'); ?> </span>
     <ul class="c-tabs-content">
       <li <?php echo $orderby == 'latest' ? 'class="active"' : ''; ?>>
        <a href="?m_orderby=latest">
            <?php esc_html_e('Latest');  ?>
        </a>
      </li>
   </ul>
</div>

0
abbas ameer 6 months 2022-02-05T03:47:14-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse