WordPress.org

Support

Support » Plugins and Hacks » Business Directory Plugin » [Resolved] [Plugin: Business Directory Plugin] Display a single field not all of them

[Resolved] [Plugin: Business Directory Plugin] Display a single field not all of them

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author businessdirectoryplugin

    @businessdirectoryplugin

    Hi sidralsideral,

    By “loop of my page”, do you mean a page where the Business Directory listings are displayed? If so, you can just customize the output choices for BD under Directory Admin->Manage Form Fields and indicate whether you want the field in the excerpt (list view) or the listing (single business listing view).

    If you’re talking about just any old random WP page, can you explain what you’re trying to do?

    I’ve created a new custom Page template.

    I just want to show the Title and a single custom form field in that page. (In example, let’s say is an actor list: I just want to show the name and the age with different css styles).

    That’s what I got:

    <?php $args=array('post_type' => 'wpbdp_listing', 'posts_per_page' => 10);
    $loop = new WP_Query( $args );
    while ($loop->have_posts()) : $loop->the_post();
    ?>
     <?php the_title();?>
    
        <?php echo get_post_meta($post->ID, 'my form field', true);?> <!-- This is the line that does not work -->
    
    <?php endwhile;?>

    Thanks

    Plugin Author businessdirectoryplugin

    @businessdirectoryplugin

    Let me ask this of my developer. Since you’re creating your own template instead of working with our own, I’m not 100% sure if this is possible or not. The API might be there and it might not…let me look into this.

    Thank you so much for your answer. I’ll wait for an answer and if I manage to solve it I’ll let you know.

    Plugin Author businessdirectoryplugin

    @businessdirectoryplugin

    OK, I’ve got an answer, from my developer:

    We don’t currently have any mechanism to allow this but what the user is trying to do is the right way to achieve it.

    The code he has doesn’t work because that’s not how we store our field values but one way to do that right now is if the user figures out the field ID inside “Manage Form Fields” by looking at the id argument in the query string when trying to edit a field and uses that ID with some of the functions we have in the plugin, like wpbdp_get_listing_field_value() or wpbdp_get_listing_field_html_value().

    Both receive as first argument the listing (post) ID and the field ID as second argument.

    For instance, if the “age” field has ID 4, he could use something like this:

    <?php $args=array('post_type' => 'wpbdp_listing', 'posts_per_page' => 10);
    $loop = new WP_Query( $args );
    while ($loop->have_posts()) : $loop->the_post();
    ?>
     <?php the_title();?>
        <?php echo wpbdp_get_listing_field_html_value($post, 4); ?>
    <?php endwhile;?>

    The difference between wpbdp_get_listing_field_value() and wpbdp_get_listing_field_html_value() is that the former retrieves the field value in raw format and the latter returns the value after some HTML transformations (for instance, turns URL field values into links and separates categories or tags linking each one to its own page).

    Hope this helps.

    Hi,

    I’m am having this same issue. I have specific requirements on how the directory listing should look and I find that I am not sure how to accomplish it. I need to be able to spit out various custom included and custom fields in a certain layout but I cannot seem to find a way through the api to get the value of a specific meta field.

    For example, I have a custom field for business address and I’m trying to make a layout for the listings view that has three columns:
    Business names, addresses and excerpts on the left, images in the middle and websites, phones and emails on the right.

    There are specific functions to grab the title, excerpt and main image, but what is the way to grab the data for the specific meta fields individually (address, website, phone) so I can render them where and how I want?

    Sorry, I started typing my question hours ago and just pushed send – I see you’ve replied to the original posters message in that time. Thanks for the response. I saw that as a way to go but wanted didn’t want to use the id if their was another way.

    Thank you so much for the answer. I’ve managed to solve the problem.

    This does not work any more, the function does not exist. And with wpbdp_formfields_api()->get_field($fieldid) I get nothing.

    Ah. echo get_post_meta(get_the_ID(), '_wpbdp[fields][$fieldid]', true); works. Well, shouldn’t $listing_id instead get_the_ID() work either?

    Plugin Author businessdirectoryplugin

    @businessdirectoryplugin

    It depends on where you are calling that function, as to whether the variable is defined or not. If you got it working with the code above, it says that you placed the code in a context where $listing_id was not defined, which is why your code worked with the changes.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] [Plugin: Business Directory Plugin] Display a single field not all of them’ is closed to new replies.
Skip to toolbar