PHP code to echo taxonomy names

WordPress Business Themes Forums Version 7 Themes DirectoryPress PHP code to echo taxonomy names

PHP code to echo taxonomy names

July 3, 2013
Steve Steve
  • Steve
    Steve
    Newbie 11 points

    Hello all…I have a taxonomy/PHP question. My DirectoryPress site is using the country/state/city taxonomy (well really just state,city taxonomy as all my listing are USA cities) and I am wanting to print for each free listing on the search results page a standard address block, i.e.:

    company name
    address line
    city, state, zipcode
    phone number

    I’ve figured out the company, address, zip code and phone number as they are just standard and custom fields, but I’m stumped on how to echo the city and state, they being taxonomies.

    Any help with the PHP code would be GREATLY appreciated.

    Thanks in advance!

    July 3, 2013 at 10:45 pm
  • patrick
    patrick
    Newbie 37 points

    hi, this is an exemple of _item.php

    <br><?php echo "Adresse : "?><?php echo get_post_meta($post->ID, 'adresse', true); ?>
    		<br><?php echo "Code postal : "?><?php echo get_post_meta($post->ID, 'cp', true); ?>
    		<br><?php echo "Ville : "?><?php echo get_post_meta($post->ID, 'ville', true); ?>
    		<br><?php echo "Téléphone : "?><?php echo get_post_meta($post->ID, 'tel', true); ?>
    		<br><?php echo "Fax : "?><?php echo get_post_meta($post->ID, 'fax', true); ?>
    		<br><?php if($custom1 != "" || $custom2 != ""){  echo '<p class="smalltags">'.get_option("display_custom_display1")." ".$custom1."  ".get_option("display_custom_display2")." ".$custom2.''; } ?>
    		<br><?php echo "Catégorie : "?> <?php the_category(' ') ?> 
    		<br><?php echo "Mots clés : "?><?php if(get_option("display_search_tags") =="yes"){ the_tags( '', '', ''); } ?>

    you do use customs fields, and the key is the name of your custom fields

    July 3, 2013 at 11:48 pm
  • Mark Fail
    Mark Fail
    Super Guru 12,812 points

    thanks for sharing :)

    July 4, 2013 at 12:44 am
  • Steve
    Steve
    Newbie 11 points

    Thanks for the reply Patrick, but I couldn’t get it to work for the city adn state simply by calling it with echo get_post_meta($post->ID, ‘city’, true) – I just get back missing lines for city and state, like the program just skipped over it.

    I know Mark mentioned that in importing records that I had to use the column header “location” and the field in the format “California,Los Angeles” (no quotes) and that worked to import city and state. But I’m still stumped on how to echo city and state on screen.

    Has anyone else done this besides the creator of the Harrogate site:

    http://www.harrogate.co.uk/category/shopping/electricals-appliances/

    THAT’s what I’m trying to achieve with my free lsitings, but the creator of that site would never get back to me, for whatever reason. So I’m trying other avenues, with no luck so far. I’m sure it’s probably a very simple line of code for someone more knowledgeable in PHP than I am.

    July 4, 2013 at 3:49 pm
  • patrick
    patrick
    Newbie 37 points

    Hi, you want just display Taxonomies on _item ? (search results page )

    July 4, 2013 at 11:02 pm
  • patrick
    patrick
    Newbie 37 points

    You can try this :
    <?php $terms = wp_get_post_terms( $post_id, $taxonomy, $args ); ?>

    July 4, 2013 at 11:04 pm
  • Steve
    Steve
    Newbie 11 points

    Hi Patrick, yes, so that city, state and zip code will show on one line as <span style=”text-decoration:underline;”>Richmond, Virginia 23221</span>

    July 4, 2013 at 11:06 pm
  • Steve
    Steve
    Newbie 11 points

    Patrick, but how exactly would I echo both city and state separated by a comma and then a space?

    July 4, 2013 at 11:10 pm
  • patrick
    patrick
    Newbie 37 points

    hi Steve,
    for do it, you can remove in my exemple <br>
    and create the custoom fields on your admin.

    this the code :

    <span style=”text-decoration:underline;”><?php echo "City : "?><?php echo get_post_meta($post->ID, 'city', true); ?>
    <?php echo "State : "?><?php echo get_post_meta($post->ID, 'state', true); ?>
    <?php echo "ZIP CODE : "?><?php echo get_post_meta($post->ID, 'zip', true); ?></span>

    you do just creat 3 CF
    1 : city with the key : city
    2 : state with the key : state
    3 : zipcode with the key : zip

    July 4, 2013 at 11:15 pm
  • patrick
    patrick
    Newbie 37 points

    You can use : &nbsp; for the space

    • This reply was modified 5 years, 11 months ago by patrick patrick.
    July 4, 2013 at 11:16 pm
  • Mark Fail
    Mark Fail
    Super Guru 12,812 points

    :)

    July 5, 2013 at 2:48 am
  • patrick
    patrick
    Newbie 37 points

    you can use this

    <?php echo "Location : "; echo get_the_term_list($post->ID,'
    location', '', '', '', true); ?>
    • This reply was modified 5 years, 11 months ago by patrick patrick.
    July 6, 2013 at 4:22 pm
  • Mark Fail
    Mark Fail
    Super Guru 12,812 points

    thanks for sharing patrick

    July 7, 2013 at 10:46 am
  • Steve
    Steve
    Newbie 11 points

    Hi Patrick, haven’t been active in the forums for a few days, but wanted to jump on an tell you I solved it! I trolled Google and WordPress.org and stumbled across the “echo get_the_term_list($post->ID,’location,~~~~~~~~~~~~) command, just as you suggested! Thank you for all of your assistance. I am most appreciative!

    Here’s what it looks like with my free listings:

    http://www.onlinehealingarts.com/?post_type=post&location=virginia&location=virginia-beach&s=

    I still can’t get the phone number to show for some reason…I did at one time and forgot what I did to have it show up. Here’s the line of code…do you see anything wrong with it? —

    "<?php if(strlen(get_post_meta($post->ID, 'bus_phone_1', true) > 2)) { ?><p class="free-address-info"><?php echo get_post_meta($post->ID, 'bus_phone_1', true) ; } ?> </p>"

    And for odd reason, on some listing the city’s before the state and on the rest it’s the state before the city. I know my all my states are parents of the cities…Mark do you have any idea why some are showing up like that?

    Thanks guys!

    July 8, 2013 at 9:14 pm
  • Steve
    Steve
    Newbie 11 points

    Let me try that line of code again…it got cut off….

    [code title=””]<?php if(strlen(get_post_meta($post->ID, ‘bus_phone_1’, true) > 2)) { ?><p class=”free-address-info”><?php echo get_post_meta($post->ID, ‘bus_phone_1’, true) ; } ?> </p>[/code]

    July 9, 2013 at 2:19 am
Viewing 15 posts - 1 through 15 (of 15 total)

Didn't find what you were after?

Chat with us now

or contact our support team