• Hi there,
    I’m trying to display meta data named company in the front end of the site. The above meta field is created using

    add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_fields' );
    
    function custom_meta_box_fields( $meta_fields ) {
        
        $meta_fields[__( 'Additional Information', 'wpsl' )] = array(
            'company' => array(
                'label' => __( 'company', 'wpsl' )
            )
        );
    
        return $meta_fields;
    }

    then I used this code in function.php

    add_filter( 'wpsl_frontend_meta_fields', 'custom_frontend_meta_fields' );
    
    function custom_frontend_meta_fields( $store_fields ) {
    
        $store_fields['wpsl_company'] = array( 
            'name' => 'company'
        );
        
        return $store_fields;
    }

    then I tried to show the company name in frontend using bellow code

    add_filter( 'wpsl_listing_template', 'custom_listing_template' );
    
    function custom_listing_template() {
    
        global $wpsl, $wpsl_settings;
        
        $listing_template = '<h5 class="Name"><%= company %></h5>' . "\r\n";
       
        return $listing_template;
    }

    After all the above steps, Search results do not appear as expected. Instead of results console error came in as company is not defined
    Error https://prnt.sc/6ZkLcgzw7a1M
    Result Page: https://prnt.sc/nvlxmG_K4Haa
    I have followed this article and this page
    Thank you

    • This topic was modified 2 years, 7 months ago by princekeshan.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi there,

    What you have done is right, but somehow it is not working, so maybe it has to do with caches. Could you try to delete transient caches in the wp store locator settings page and see if it works? Also, if you are using any other caching pluign, consider disabling it for the pages where you show the wp store locator.

    Get back to us if that does not solve your issue!
    Regards,

    Thread Starter princekeshan

    (@princekeshan)

    Even After I remove the transient cache, the Still issue is remaining. Can you Please have a look

    Thread Starter princekeshan

    (@princekeshan)

    When I try to access meta data using PHP code bellow

    <?php
    $appointment_url = get_post_meta( $queried_object->ID, 'wpsl_url', true );
    if ( $appointment_url ) {
      echo '<p><a href="' . esc_url( $appointment_url ) . '">' . __( 'Make Appointment', 'wpsl' ) . '</a></p>';
    }
    else{ echo "not working"; }?>

    It’s showing the not working message.

    Please have a look at this, This one is super urgent.

    Hi there,

    Your code looks ok to me, so I don’t know what the issue could be. Maybe you can write us a support ticket and give us more information on your website, so we can take a look at it ourselves.

    Thanks!

    @princekeshan I have experienced similar behaviour, try dragging the start marker a little too force location update (or manually enter location and press search). I started not getting meta displayed without changing any settings but it seems to be related to the results being generated without a start location being passed.

    Out of interest when I disabled the “Load locations on page load:” setting the custom meta was loaded but I’m not able to understand why this is. Anyways, hope that helps with your debugging.

    We figured this out. In the end it all came down to this line being missed in functions.php:

    add_filter( ‘wpsl_frontend_meta_fields’, ‘custom_frontend_meta_fields’ );

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display Meta Data in frontend’ is closed to new replies.