Hi, I wonder if someone can help with the code below on Sorting posts (that exists in a specific category) by a custom field, but only if the custom filed exists, otherwise just have the posts (within the specific category) display as usual.
In addition, all posts should wrap in
Here's the code so far:
<ul class="products"> <?php global $post; $page_category = 4; $args = array('category'=>$page_category,'meta_key'=>'sorter','orderby'=>'meta_value_num','order' =>'ASC'); $page_content = get_posts( $args ); foreach( $page_content as $post ) : setup_postdata($post); ?> <li><?php the_title(); the_content(); ?></a></li> <?php endforeach; ?> </ul>
The code above will not show posts if the custom filed 'sorter' doesn't exist.
Any help would be very much appreciated!