• i want to create a list of posts from category XYZ, and sort them alphabetically based on what’s contained in the VALUE field of a custom field called “studentname“.

    i tried this code and it didnt work. any idea what’s wrong? thanks in advance.

    <?php
    
      	$loop = new WP_Query( array(
        		'showposts' => 5,
        		'post_type' => 'studentname',
        		'category_name' => XYZ,
    		'orderby' => 'meta_value',
    		'meta_key' => 'studentname'
        		)
        		);
      	while ( $loop->have_posts() ) : $loop->the_post(); ?>
       	<div>
          		<h2><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        	</div>
      <?php endwhile; ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wp_query with custom fields’ is closed to new replies.