문제

I'm using query_posts to sort order certain categories. My code look like this:

query_posts('category_name=abs&orderby=meta_value_num&meta_key=field_ordering&order=DESC');

This does show post in exact sorting model as I specify. However, query above doesn't display that post doesn't have meta_key 'field_ordering' set in database.

My problem is, I don't want to set it on ALL post, but I still can display the data.

Any solutions?

도움이 되었습니까?

해결책

Well, you can't sort by field that isn't there. You can modify query conditionally only in those categories which have that field and let default query work in rest.

It would be something like:

if( is_category('abs') )
    query_posts(
    array_merge(
    array('orderby' => 'meta_value', 
                  'meta_key' => 'field_order', 
                  'order' => 'Desc' ),
    $wp_query->query
        )
    );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top