WordPress.org

Ready to get started?Download WordPress

Forums

Sort post by custom field alphabetically (8 posts)

  1. romuloctba
    Member
    Posted 1 year ago #

    Hi ther everybody.
    I have searched all arround for a awnser to this. Even thoug i found some clues using another kind of loop structure, directly from db i didn't get it

    I have this code:

    <?php $argsvs = array(
           	      		'post_type' => 'imovel-para-venda',
           	      		'meta_key' => 'wpcf-imovel-preco',
           	      		'posts_per_page' => 0,
           	      		 'oderby' => 'meta_value',
           	      		 'order' => 'DESC'
    					 );
    $loop = new WP_Query( $argsvs );
    while ( $loop->have_posts() ) : $loop->the_post();
    ........
    and so on

    the thing is that the custom field wpcf-imovel-preco was created using the plugin Types, and it is a text field. Usually, it is used to put numbers, but sometimes filled with words too.

    Anyone could help me find the way to order my loop by that custom field? Alphabetically, i think?

  2. romuloctba
    Member
    Posted 1 year ago #

    I'm still looking, and i think probably i will do it with Meta_query but i couldn't find how to do it yet

  3. romuloctba
    Member
    Posted 1 year ago #

    The good news is that a nice stackoverflow user showed me that I was missin and 'r' in 'orderby'.....
    the bad news is that
    the values are like: 100.000.00 and 120.000,00..... but 1.200.000,00 apeears before 100.000,00 , any idea how to fix this?

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

    What number is 1.200.000,00 supposed to represent?

    My post was blank at one moment because I retracted my comment.

  5. romuloctba
    Member
    Posted 1 year ago #

    oh, dude, i loved your awnser!
    (lol, it is in blank here )

  6. romuloctba
    Member
    Posted 1 year ago #

    ok, it apears now!
    well 1.200.000,00 is 1,200,000.00 in brazilian notation
    we use . instead of , and , instead of .

  7. romuloctba
    Member
    Posted 1 year ago #

    1.200.000,00 = 1.2 milion ^^

  8. romuloctba
    Member
    Posted 1 year ago #

    no prob for the blank post hehehe, any ideas that could help me do that? (thanks for awnsering, btw!)

Topic Closed

This topic has been closed to new replies.

About this Topic