All Property Types
-
In
span.listing-property-typethere is only one property type included even if there are multiple property types selected for that property. I need all the property types included for my add-on code to work properly (filtering by property type). Any change I can make to the PHP to fix that?
-
In the widget?
There is this line, which pulls only one property type taxonomy term due to display limitations in the widget:
$loop .= sprintf( '<span class="listing-property-type">%s</span>', wp_listings_get_property_types() );If you want to display more than one, use get_the_term_list. Ex:
get_the_term_list( $post->ID, 'property-types', '', ', ', '' );I found a work around myself regarding my own code and website set up. I’m sure what you suggested works, so I appreciate the response. π
On second thought, this would still be handy. Where would I use get_the_term_list?
If possible, can you tell me the exact file I have to modify?
Bump. This is now urgent!
The above referenced code is in the file /includes/class-featured-listings-widget.php at around line 106.
That did not help the issue. I did the following:
$loop .= sprintf( '<span class="listing-property-type">%s</span>', wp_listings_get_property_types() );
became this:
$loop .= sprintf( '<span class="listing-property-type">%s</span>', get_the_term_list( $post->ID, 'property-types', '', ', ', '' ) );And I still only see one Property Type when there are two selected for some listings.
-
This reply was modified 9 years, 7 months ago by
mikopia.
Any suggestions/ideas?
Ok, actually the line you need to change is the line that references wp_listings_get_status()
This line:
$loop .= sprintf( '<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status())), wp_listings_get_status() );Change to:
$loop .= sprintf( '<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status())), wp_listings_get_status($post->ID, 1) );No, it is
span.listing-property-typethat has the property types. There is nospan.listing-status. I just needspan.listing-property-typeto display all property types selected for that property, not just one.The code you just sent me will not do that since I see
span.listing-statusin there and notspan.listing-property-typeWell then unfortunately there is no way to do this unless you write your own function.
Why does the first suggestion not work? That seems to be what I want. You said the code you suggested would pull all the property types (even though it didn’t)…
-
This reply was modified 9 years, 7 months ago by
mikopia.
Not quite sure, but that’s actually not what you want either, because if you look at the documentation, that would return them all wrapped in anchor tags linked to their respective term archive pages: https://codex.ww.wp.xz.cn/Function_Reference/get_the_term_list
Does that mean I can use the output of
get_the_term_listand play with it a little to get what I want? Or is this something you could implement into the plugin at some point in the future? I’m not very familiar with PHP.Ok, so here is what you can do. Keep in mind this is not supported and we have no plans to add this functionality into the plugin.
In the file /includes/functions.php is the function
wp_listings_get_property_types():/** * Displays the property type (residential, condo, comemrcial, etc) of a listing */ function wp_listings_get_property_types($post_id = null) { if ( null == $post_id ) { global $post; $post_id = $post->ID; } $listing_property_types = wp_get_object_terms($post_id, 'property-types'); if ( empty($listing_property_types) || is_wp_error($listing_property_types) ) { return; } foreach($listing_property_types as $type) { return $type->name; } }You can modify that function to return all the terms for a post. It’s recommended to copy the function to your theme or a site specific plugin and rename it, so it doesn’t get overwritten in an update. You would change that function like so:
/** * Displays the property type (residential, condo, comemrcial, etc) of a listing */ function wp_listings_get_property_types($post_id = null) { if ( null == $post_id ) { global $post; $post_id = $post->ID; } $listing_property_types = wp_get_object_terms($post_id, 'property-types'); if ( empty($listing_property_types) || is_wp_error($listing_property_types) ) { return; } $prop_types = ''; foreach($listing_property_types as $type) { $prop_types .= $type->name . '<br />'; } return $prop_types; } -
This reply was modified 9 years, 7 months ago by
The topic ‘All Property Types’ is closed to new replies.