WordPress.org

Ready to get started?Download WordPress

Forums

Business Directory Plugin
[resolved] Display a single field not all of them (12 posts)

  1. sidralsideral
    Member
    Posted 1 year ago #

    Hello,

    I wonder how could I display a single field (let's say, for example, a field called "age") in the loop of my page. I'm not interested in displaying all the Listing Fields, just one of them.

    It should be something like <php? the_field ('age'); ?> but I don't manage to find it.

    Thank you for your attention,

    Greetings

    http://wordpress.org/extend/plugins/business-directory-plugin/

  2. businessdirectoryplugin
    Member
    Plugin Author

    Posted 1 year ago #

    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?

  3. sidralsideral
    Member
    Posted 1 year ago #

    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

  4. businessdirectoryplugin
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  5. sidralsideral
    Member
    Posted 1 year ago #

    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.

  6. businessdirectoryplugin
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  7. kidmeke
    Member
    Posted 1 year ago #

    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?

  8. kidmeke
    Member
    Posted 1 year ago #

    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.

  9. sidralsideral
    Member
    Posted 1 year ago #

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

  10. bjo
    Member
    Posted 11 months ago #

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

  11. bjo
    Member
    Posted 11 months ago #

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

  12. businessdirectoryplugin
    Member
    Plugin Author

    Posted 11 months ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags