• Just started with php and wordpress so any help is welcome.

    Here is my setup. I have categories made of cities: paris, london etc. I have also custom field called “Location”. This is because I list restaurants I like. The location custom field is the name of the restaurant in the city. So I make a new post about restaurant X, select the Paris category and add a custom field Location of the name of the Restaurant.

    So basically I have for that example
    Category=Paris
    custom-field”location”=BaconParadise

    Now I would like to have a page/post where I could put a custom php query that would basically list ALL the “Locations” in that city. Something like

    Select all the PARIS posts that have a LOCATION field and list them one by one on a single page but do not allow duplicates. Could someone be kind enough to help me write a query that would do that? Thank you so much in advance I am pulling my hair trying to make it work.

    It should look like:

    Paris Restaurants
    – restaurant 1
    – restaurant 2
    etc… thanks in advance

Viewing 1 replies (of 1 total)
  • Thread Starter Amnolith

    (@amnolith)

    I cam up with something like this

    <?php query_posts('posts_per_page=20&category_name=New York&meta_key=Location&order=DES'); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php $links = get_post_custom_values("Location");
    if ($links[0]!="") {
     $mykey_values = get_post_custom_values('Location');
     foreach ( $mykey_values as $key => $value )
       {
    echo $value;
    echo "<br><br>";
       }
    
    }
    ?>

    but I still get duplicates as sometimes the restaurants appears two or three times? What is the best way to not have duplicates in the query? Thanks in advance

Viewing 1 replies (of 1 total)
  • The topic ‘Need help making custom field query (category custom field)’ is closed to new replies.