WordPress.org

Ready to get started?Download WordPress

Forums

Sort by custom field (4 posts)

  1. smoczokwik
    Member
    Posted 7 years ago #

    I tried to use Mike Smullin's "Sort Categories By Title" plugin to sort posts according to the value of the custom field "parag" which is a 4 digit number and modified the code to this:

    add_action('pre_get_posts','sort_categories_by_title');
    
    function sort_categories_by_title($x) {
    	if(in_category(4)) {
    		$x->query_vars['orderby'] = 'parag';
    		$x->query_vars['order'] = 'ASC';
    	}
    }

    I want to sort them only when displaying one category (#4 in this case) and then sorted by "parag" whatever value it has.

    Help please!

    ps. I tried is_category, in_category and a different custom value field but none of this seems to work. It also doesn't seem as if I have to call the function since it is included in the action call.

  2. Dgold
    Member
    Posted 7 years ago #

    Unfortunately i don't know, but a forum guy named Kafkaesqui helped me a lot with custom fields in the past, I think he could explain how, if he comes on here.

  3. MichaelH
    Member
    Posted 7 years ago #

  4. krille83
    Member
    Posted 7 years ago #

    Hi!

    I'm using the plugin above, but have a small problem. I'm using a custom field call 'pris' that contains any number for example 354.

    Now i want to sort the post by that number, starting with the lowest. Couldn't get the plugin to sort properly, any suggestions on how to fix that?

Topic Closed

This topic has been closed to new replies.

About this Topic