Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Custom Field Search.

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29980
    Ted
    Member

    Hi there!
    I guess this is the only place i can get some answers …

    Well i have developing a wordpress website… and i am using alot of custom fields…and they have worked very good until i needed to create a filter/search from using them …
    so far … not good… i had used plugins to create it but they are not that flexible …
    i am not used to do this… so can any one help me!?

    The idea:

    get custom fields to combobox
    do a search by the selects.

    The Code:
    i have done this ( not working …. )

    ( cicle to get all the costum fields names )
    <?php
    global $post;
    $tmp_post = $post;
    $myposts = get_posts(‘child_of=1’);
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    <?php $option[] = get_post_meta($post->ID,’Concelho’, true);
    $Concelho=array_unique($option); sort($Concelho); ?><!–Concelho–>
    <!–Tipo de Imovel –>
    <?php $old_estado[] = get_post_meta($post->ID,’Estado’, true);
    $estado=array_unique($old_estado); sort($estado); ?><!–Estado –>

    <?php $old_quartos[] = get_post_meta($post->ID,’Quartos’, true);
    $quartos=array_unique($old_quartos); sort($quartos); ?><!–Quartos–>

    <!–Preço minimo –>
    <?php $old_preco[] = get_post_meta($post->ID,’Preco’, true);
    $preco=array_unique($old_preco); sort($preco); ?><!–Preço minimo –>

    <!–Preço maximo –>
    <?php $old_referencia[] = get_post_meta($post->ID,’Referencia’, true);
    $referencia=array_unique($old_referencia); ?><!–referencia –>

    <?php endforeach; ?>

    ( form )

    <form role="search" method="get" id="searchform" action="<?php bloginfo(‘siteurl’); ?>">
    <div>
    <?php
    $cbox = ‘<select name="Concelho" style="width:291px; height:25px; text-align:left; font-size:9pt; padding-top:3px; margin-top:10px;">’;
    foreach($Concelho as $key=>$val) :
    $cbox .='<option value="’.$val.’" selected="false">’.$val.'</option>’;
    endforeach;

    $cbox .='<option value="" selected="true" >’.Seleccione." ".o." ".Concelho.'</option>’;
    $cbox .= ‘</select>’;
    echo $cbox;
    ?>

    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>

    you can check the site here…

    http://serverprovider.com/low-cost

    Thanks in advanced i hope you can help me!

    #81777
    Ted
    Member

    any one ? :X

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.