A A A

Please consider registering
guest

Log In Register

Register | Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 3 characters - maximum search word length is 84 characters

Topic RSS
Advanced customization of the List and Detail Views of BD
Business Directory Support
Admin
May 13, 2013 - 6:29 pm
Member Since: July 6, 2011
Forum Posts: 1399
Offline

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:

$field = wpbdp_get_form_field( 4 );
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:

$field = wpbdp_get_form_field( 4 );
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.

Documentation: http://businessdirectoryplugin.com/docs FAQ: http://businessdirectory.com/support-forum/faq
Forum Timezone: UTC 0

Most Users Ever Online: 103

Currently Online: bizdirectorysupport, pxwm, ls1086
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Member Stats:

Guest Posters: 1912

Members: 629

Moderators: 0

Admins: 1

Forum Stats:

Groups: 1

Forums: 4

Topics: 3718

Posts: 16047

Newest Members: Candi

Administrators: Business Directory Support (1399)

Directory powered by Business Directory Plugin