Hey regme,
You have a few syntax errors and I’m unsure if your first function is valid, single_cat_title probably isn’t what you’re looking for. Try starting by hardcoding a category ID into your function to be sure it works. You can then replace it with a function once you know the rest of your code operates normally.
I removed an extra semicolon and an extra comma.
<?
$catid = 1; //The Category with ID = 1
$args = array(
'cat' => '$catid', //Only show this category
'post_type' => 'post', //Only show posts
'meta_key' => 'MY_KEY', //Display posts with a custom field of "MY_KEY"
'orderby' => 'meta_value_num', //Sort by the numeric value of MY_KEY
'order' => 'DESC' //Descending order
);
query_posts( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><br /><?php
endwhile;
endif;
wp_reset_query();
?>
As a heads up – I only did a spot check of your code and haven’t been able to test it. I’m not exactly sure how you’re trying to sort so I hope this helps get you started.
I suggest checking out this resources as well: http://www.billerickson.net/code/wp_query-arguments/
Cheers!
-Tyler
Thread Starter
regme
(@regme)
Tyler Shadick, thanks for reply! You have helped me figer out the reason.
This code is good for me^
$args = array(
'post_type' => 'post',
'cat' =>get_query_var('cat'),
'meta_key' => 'META_KEY',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $paged,
);