Support

Account

Home Forums General Issues how to query by asc or des

Solved

how to query by asc or des

  • im use AFC for my rating in my website
    now i want to query my post by rating
    ex post1 = 3 star
    post2 = 4 star
    post3 = 1 star

    this is what i want (query with rating)
    1st post2 (4 star)
    2nd post1 (3 star)
    3rd post 3 (1 star)

    this is my field
    Field Label* = star rating
    Field Name* = star_rating
    Field Type* = text
    Default Value = star_rating

    i have to read this guild http://www.advancedcustomfields.com/resources/orde-posts-by-custom-fields/

    but i don’t know what is ‘post_type’ or meta_key’
    i don’t know how to use php can u show me example code?

    are you understand? sorry for my bad english
    i hope anyone can help me 😀
    thank you

  • Hi,

    at first.

    post_type is the Type of the Post. That means post_type = “post”, if you create post with normal wordpress features.
    Here the Codex

    For example the Navigation Elements are an other post_type. Beside that there are custom Post Types.

    meta_key is the key in the database. In ACF the key of Single Fields is always the name of their field.But you don’t need the key. Because the Star Field is linked with the post.

    I think you create a post and have the star_rating field for each post. So you have to query all posts with the post_type =”post”.

    $posts = get_posts(array(
    	'post_type'			=> 'post',
    	'posts_per_page'	=> -1,
    	'orderby'			=> 'star_rating',
    	'order'				=> 'DESC' 
    ));

    Hope It helps.

  • thanks you! very much UKF!^_^

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘how to query by asc or des’ is closed to new replies.