0

Hello I have custom wp query

$args = array('post_type' => 'marketing_en',
    'tax_query' => array(
     array(
     'taxonomy' => 'custom_post_type', 
     'field' => 'slug',
     'terms' => array(ICL_LANGUAGE_CODE == 'ar' ? 'tool-ar' : 'tool'),
      ),),);
    $loop = new WP_Query($args); 
 
    while ( $loop->have_posts() ) : $loop->the_post();

And i need to order posts by oldest post or by number in post "see image"

I tried to add 'orderby' to the array but it is not working with me. i want for ex the title '01 concepts' to be the first in the left.

enter image description here

1 Answer 1

0

To sort by title in ascending order (alphabetical order), you can use orderby => title and order => ASC:

$args = array(
    'post_type' => 'marketing_en',
    'orderby' => 'title',
    'order' => 'ASC',
    'tax_query' => array(
        array(
            'taxonomy' => 'custom_post_type', 
            'field' => 'slug',
            'terms' => array(ICL_LANGUAGE_CODE == 'ar' ? 'tool-ar' : 'tool'),
        ),
    ),
);
$loop = new WP_Query($args); 
 
while ( $loop->have_posts() ) : $loop->the_post();

Make sure you have the correct values in the post_type and taxonomy fields. The value of post_type should be the custom post type you are querying and the taxonomy should be the correct taxonomy associated with your posts.

1
  • Working! thank you a lot Jul 21, 2023 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.