Issue With Custom Meta Fields (not showing on single listings)

Easy Property Listings WordPress Real Estate Plugin Forums Priority Support Issue With Custom Meta Fields (not showing on single listings)

Viewing 11 posts - 1 through 11 (of 11 total)

These forums are closed to new replies / tickets. Please open a support ticket from our new Support page.

  • Author
    Posts
  • #16029
    Billy Waller
    Spectator

    Hello Merv,

    I have tried what you have listed here
    http://easypropertylistings.com.au/docs/epl_listing_meta_boxes-filter-all-available-meta-fields/
    and can’t seem to figure out how to make the fields show up on the front end. I keep getting all sorts of fatal errors. I’m don’t really know what I’m doing when it comes to PHP so it may just be a syntax thing. If you could look at my code and help me out I would greatly appreciate it!

    #16031
    Billy Waller
    Spectator
    This reply has been marked as private.
    #16039
    Merv Barrett
    Keymaster

    Example to return a single variable:

    function my_output_property_weeks_available_number() {
            global $property; // Use the listing custom meta and access EPL functions
            
            $label = 'Number of weeks available'; // Your custom label
            $key = 'property_weeks_available_number'; // Variable Key
            $value = $property->get_property_meta( $key ); // Get the variable value
    
            if ( empty ( $value ) ) // Close function if the $value is empty
                   return;
    
            echo $label . ': ' . $value; // Will output : Number of weeks available: 3
    }

    Now you can use your new function in your template

    <?php my_output_property_weeks_available_number(); ?>

    Or you can automatically output this variable on the template using a hook

    add_action( 'epl_property_tab_section_after' , 'my_output_property_weeks_available_number' )

    • This reply was modified 8 years, 8 months ago by Merv Barrett.
    #16063
    Billy Waller
    Spectator

    Thanks for the fast reply! that worked. One issue, I am getting a syntax error while printing the label. I got rid of the ‘: ‘ in the echo and it worked, but I would like for the colon to be there. What is the correct syntax?

    #16064
    Merv Barrett
    Keymaster

    I recommend placing your functions in a custom plugin instead of your theme. Which you can download from here

    There is an example here on how to output your select options

    #16066
    Merv Barrett
    Keymaster

    I forgot a . (updated above to echo $label . ‘: ‘ . $value;)

    #16101
    Billy Waller
    Spectator

    Sorry to keep bugging you with this. I am having issues outputting select options and radio button options.
    this is what my output function looks like.

    function my_output_use_type_select() {
            global $property; // Use the listing custom meta and access EPL functions
            
            $label = 'Use Type'; // Your custom label
            $array = array(
    		'select_1'  =>   'Annual Fixed Week',
            'select_2'  =>   'Annual Floating Week',
            'select_3'  =>   'Bi-Annual Fixed Week (even yr.)',
            'select_4'  =>   'Bi-Annual Fixed Week (odd yr.)',
    		'select_5'  =>   'Bi-Annual Floating Week (even yr.)',
            'select_6'  =>   'Bi-Annual Floating Week (odd yr.)',
            'select_7'  =>   'Vacation Rental',
        );
            $key = $property->get_property_meta('use_type_select');
     
        $value = array_key_exists( $key , $array ) && !empty( $array[$key] )  ? $array[$key] : '';
     
        echo $label. ': '.$value;
    }
    
    add_action( 'epl_property_tab_section_before' , 'my_output_use_type_select' );

    And this is what it is producing

    How can I make it display the values? Also, in the hook, can I add a CSS class?

    I installed the plugin, but I was having issues transferring everything over to it so I stopped as I am on a deadline. I will try to do that later on.

    Thanks!

    #16131
    Merv Barrett
    Keymaster

    Looks like your meta key in your code is property_use_type_select but your above function was use_type_select. I’ve adjusted your code and it now outputs. Well done btw

    Yes you can add anything you want to the output in relation to CSS or html wrappers. Either echo the value or the value + a wrapper.

    You may want to wrap all your values in list items, just make sure you wrap them in opening and closing ul

    echo <li class="my-list-item">$label. ': '.$value . '</li>';

    #16132
    Merv Barrett
    Keymaster

    Instead of outputting each function using the filter, you are better off building a single filter that outputs all the values. Off course this all depends on what you are trying to do.

    so instead of using echo $label. ': '.$value; in your functions use return $label. ': '.$value;

    Or add a list item to output them all as an ordered list, return '<li>' . $label. ': '.$value . '</li>';
    Now what will happen is when that function is run nothing will output but the function will return your Label + value

    eg

    function my_output_ownership_type_radio() {
            global $property; // Use the listing custom meta and access EPL functions
            
            $label = 'Ownership Type'; // Your custom label
            $array = array(
    	'option_1'  =>   'Leased',
            'option_2'  =>   'Deeded',
            'option_3'  =>   'Perpetuity',
        );
            $key = $property->get_property_meta('ownership_type_radio');
     
        $value = array_key_exists( $key , $array ) && !empty( $array[$key] )  ? $array[$key] : '';
    
        if ( $value != '' ) { // Make sure there is a value
            return '<li>' . $label. ': '.$value . '</li>';
        } else {
            return; // Return nothing
        }
    }
    // Remove the filter
    

    Now you can build a single function to do the output and use a single hook

    function my_extra_features_output() {
         $output = '<ul class="my-special-features">'; //Open List
    
         // .= adds to the variable
         $output .= my_output_property_check_in_date_select();
         $output .= my_output_sale_type_select();
         $output .= my_output_season_select();
         $output .= my_output_use_type_select();
         $output .= my_output_facility_type_select();
         $output .= my_output_sleeps_number_select();
         $output .= my_output_ownership_type_radio(); // etc
    
         $output .= '</ul>'; // Close list
        
         echo $output;
    }
    add_action( 'epl_property_tab_section_before' , 'my_extra_features_output' );

    This allows you to control the order of the values that are output.

    Its better to include the list item in each of your child functions because each will return nothing if they are empty.

    You can also output the values in various formats, take the get_property_bed function in EPL as an example:

    function get_property_bed($returntype = 'i') {
    	if($this->get_property_meta('property_bedrooms') == '')
    		return;
    	$bed['i'] = '<span title="'.__('Bedrooms', 'epl').'" class="icon beds"><span class="icon-value">'. $this->get_property_meta('property_bedrooms') . '</span></span>'; 
    	$bed['d'] = $this->get_property_meta('property_bedrooms') . ' '.__('bed', 'epl').' ';
    	$bed['l'] = '<li class="bedrooms">' . $this->get_property_meta('property_bedrooms') . ' '.__('bed', 'epl').'</li>';
    	return $bed[$returntype];
    }

    This function allows us to specify the returntype, and can output the list type:

    get_property_bed('l')

    Would return
    '<li class="bedrooms">' . $this->get_property_meta('property_bedrooms') . ' '.__('bed', 'epl').'</li>';

    • This reply was modified 8 years, 8 months ago by Merv Barrett.
    • This reply was modified 8 years, 8 months ago by Merv Barrett.
    #16134
    Billy Waller
    Spectator

    Thanks so much! you’re a lifesaver!

    #16136
    Merv Barrett
    Keymaster

    Thanks Billy, also browse Easy Property Listings on GitHub as there are a number of functions that can either be used or copy/paste and edited to suit what you need.

    Particularly the property class is full of examples which you can adapt:

    class-property-meta.php
    These functions need to be called using $property->FUNCTION_NAME();

    • This reply was modified 8 years, 8 months ago by Merv Barrett.

These forums are closed to new replies / tickets. Please open a support ticket from our new Support page.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Priority Support’ is closed to new topics and replies.