WARNING: This guide is meant to help users who are already trying to customize the templates supplied with BD to echo specific fields in specific places. If you are not an advanced PHP programmer with strong HTML skills and knowledge of the WordPress API, using code in this section may break your BD directory. This information is intended for programmers only.
This article is a supplement of this one here: http://businessdirectoryplugin…..our-theme/
Getting data out of BD to display specific fields
wpbdp_get_form_field( $field_id ) receives as argument the ID of the field you want to work with and returns a field object. You can then use the display() function on this object to get the HTML as it would be printed by BD when displaying this field inside a listing. This function receives as argument the ID of the listing.
So, if you want to print, say, the HTML output for the field with ID 4 with the data obtained from the listing with ID 255, you can do the following:
echo $field->display( $listing_id );
display() doesn't print things automatically. It just returns the HTML so you have to use it in a print or echo statement if you want to actually see the output.
Using the display() function to output HTML vs. Field Values
display() doesn't return the actual value of the field as it is stored in metadata or whatever. This function is meant to display the field in a listing's page or excerpt.
If you want the value as it is in the database you have to use the value( $post_id ) function or the auxiliary functions html_value( $post_id ) or plain_value( $post_id ). All of these functions receive as argument the listing ID and only return the value so once again, echo or print is needed to actually see the stuff on the screen.
As the names suggest, value() returns the raw value from the database, html_value() gives you a HTML output (most of the time this is what you want) and plain_value() returns a plain-text version of the value.
Going back to the previous example, this is what you have to do if you want to print the field's value instead of displaying the whole field:
echo $field->value( $listing_id );
All the _value() functions return the same thing most of the time (at least for meta fields) but things can be very different in other cases. For instance, calling ->value() on a category field will returns the taxonomy term IDs for the categories the listing is in, ->html_value() will return the comma-separated list of categories with links to each category page (as you are used to see) and finally ->plain_value() returns a comma-separated list of categories without links. It is important to keep this in mind because the actual output depends both on the field type and the association.
Most Users Ever Online: 103
Currently Online: bizdirectorysupport, pxwm, ls1086
Currently Browsing this Page:
Guest Posters: 1912
Newest Members: Candi
Administrators: Business Directory Support (1399)