Skip Navigation

[Resolved] Front end listing and post view

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 7 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#460860

Hello all,

I have problem with frontend view. I'm using custom listing page but I canot get any data from custom fields to appear on item. This is the my listing template. What I need to do or What I'm doing wrong?

Thank you

<?php

    /*
    Template Name: Boat listing
    */

	if ( !defined('ABSPATH') ){ die(); }

	get_header();

        if ( ! function_exists( 'get_theme_currency' ) ) {
            /**
             * Get Currency
             *
             * @return mixed|string|void
             */
            function get_theme_currency() {
                $currency = get_option( 'theme_currency_sign' );
                if ( ! empty( $currency ) ) {
                    return $currency;
                }
                return __( '€', 'framework' );
            }
        } ?>

		<div class='container_wrap container_wrap_first main_color boats_container <?php avia_layout_class( 'main' ); ?>'>

			<div class='container'>

				<main class='template-page content <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content','post_type'=>'page'));?>>


                    <h1></h1>

                    <?php
echo '<div class="search-filter-form-container">';
echo do_shortcode('[searchandfilter id="16439"]');
echo '</div>';
                        $args = array( 'post_type' => 'property', 'posts_per_page' => 18, 'order' => 'ASC' );
$args['search_filter_id'] = 16439;
                        $loop = new WP_Query( $args );

                        echo '<div class="boats">';

                        while ( $loop->have_posts() ) : $loop->the_post();

                            $id = get_the_ID();

                            $post_meta_data = get_post_custom($id); ?>

                                <div class="boats__item">

                                    <div class="boats__item_container">

                                        <figure class="boats__figure">

                                            <?php if( has_post_thumbnail() ){

                                                the_post_thumbnail('listings');

                                            } else {

                                                echo '<img src="<em><u>hidden link</u></em>" alt="">';

                                            } ?>

                                            <a href="<?php the_permalink() ?>" class="boats__figure_btn">Details</a>

                                        </figure>

                                        <div class="boats__data">

                                            <h3 class="boats__title"><?php echo the_title() ?></h3>

                                            <?php if( !empty($post_meta_data['wpcf_yacht_marina'][0]) ) {
                                                $marina_id = $post_meta_data['wpcf_yacht_marina'][0];
                                                $marina_post    = get_post( $marina_id );
                                                echo '<span class="boats__marina">';
                                                    echo '<span class="icon icon-pin"></span>';
                                                    echo esc_html(  $marina_post->post_title );
                                                echo '</span>';
                                            } ?>

                                            <span class="boats__week">
     <span class="icon icon-calendar"></span>

     <?php
          $week = wp_get_post_terms($post->ID, 'week', array("fields" => "all"));
         echo $week[0]->name ;
     ?>

</span>

                                            <span class="boats__price">

                                                <?php

                                                    $price = get_property_price();

                                                    if ( $price ){
                                                        echo $price;
                                                    }

                                                ?>

                                            </span>

                                        </div>

                                        <aside class="boats__aside">

                                            <?php if( !empty($post_meta_data['wpcf_property_size'][0]) ) {

                                                $prop_size = $post_meta_data['wpcf_property_size'][0];
                                                $prop_size_postfix = $post_meta_data['wpcf_property_size_postfix'][0];
                                                $boat_label = __( 'Boat Length', 'framework' );

                                                echo '<span class="boats__aside_item">';
                                                    echo '<span class="icon icon-sailing-boat"></span>';
                                                    echo '<span class="boats__aside_value">';
                                                    echo esc_html( $prop_size );
                                                    echo '</span>';
                                                  echo '</span>';
                                            } ?>

                                            <?php if( !empty($post_meta_data['wpcf_property_bathrooms'][0]) ) {

                                                $prop_bathrooms = $post_meta_data['wpcf_property_bathrooms'][0];
                                                $bathrooms_label = __( 'Year','framework' );

                                                echo '<span class="boats__aside_item">';
                                                    echo '<span class="icon icon-tool"></span>';
                                                    echo '<span class="boats__aside_value">';
                                                    echo esc_html( $prop_bathrooms );
                                                    echo '</span>';
                                                echo '</span>';
                                            } ?>

                                            <?php if( !empty($post_meta_data['wpcf_property_bedrooms'][0]) ) {

                                                $prop_bedrooms = $post_meta_data['wpcf_property_bedrooms'][0];
                                                $bedrooms_label = ($prop_bedrooms > 1)? __('Cabins','framework' ): __('Cabin','framework');

                                                echo '<span class="boats__aside_item">';
                                                    echo '<span class="icon icon-bed"></span>';
                                                    echo '<span class="boats__aside_value">';
                                                    echo esc_html( $prop_bedrooms );
                                                    echo '</span>';
                                                echo '</span>';
                                            } ?>

                                            <?php if( !empty($post_meta_data['wpcf_yacht_guests'][0]) ) {

                                                $prop_guest = $post_meta_data['wpcf_yacht_guests'][0];
                                                $guest_label = ($prop_garage > 1)?__('Guests','framework' ): __('Guest','framework');

                                                echo '<span class="boats__aside_item">';
                                                    echo '<span class="icon icon-people"></span>';
                                                    echo '<span class="boats__aside_value">';
                                                    echo esc_html( $prop_guest );
                                                    echo '</span>';
                                                echo '</span>';
                                            } ?>

                                            <?php if( !empty($post_meta_data['wpcf_yacht_deposit'][0]) ) {
                                                $prop_deposit           = $post_meta_data['wpcf_yacht_deposit'][0];
                                                $currency               = get_theme_currency();
                                                $decimals               = intval( get_option( 'theme_decimals' ) );
                                                $decimal_point          = get_option( 'theme_dec_point' );
                                                $thousands_separator    = get_option( 'theme_thousands_sep' );
                                                $currency_position      = get_option( 'theme_currency_position' );
                                                $formatted_price        = number_format( $prop_deposit, $decimals, $decimal_point, $thousands_separator );

                                                if ( $currency_position == 'after' ) {
                                                    $prop_deposit       = $formatted_price . $currency;
                                                } else {
                                                    $prop_deposit       = $currency . $formatted_price;
                                                }

                                                $deposit_label  = __( 'Deposit', 'framework' );

                                                echo '<li class="boats__aside_item">';
                                                    echo '<span class="icon icon-credit-card-alt"></span>';
                                                    echo '<span class="boats__aside_value boats__aside_value--small">';
                                                    echo esc_html(  $prop_deposit );
                                                    echo '</span>';
                                                 echo '</li>';
                                            } ?>

                                        </aside>

                                    </div>

                                </div>

                            <?php

                        endwhile;

                        echo '</div>';

                        wp_reset_query();

                    ?>

				</main>

				<?php /* get_sidebar(); */ ?>

			</div>

		</div>

<?php get_footer(); ?>

#461043

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Renato

It is not obvious what is missing or wrong with your template code.

I suggest you add some debug logging throughout your code to check whether the key variables match what is expected.

I assume you know how to, but if you haven't already, edit your wp-config.php file and change the line with WP_DEBUG like so:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

That will create a debug.log file in your wp-content directory which you can examine in any text editor.

Now add a few error_log messages at suitable points, checking, for example, what is the $loop when it is declared, and, in particular, checking $post_meta_data to see what it contains.

(For better formatting, add them to your logs like so: error_log(print_r($loop, true));)

You need to verify that the source data is present and in the expected format when retrieved and manipulated. Sprinkling debug messages as above throughout your code should help identify the problem, and is a simpler alternative than using a fully-fledged debugging tool such as netbeans or phpstorm.

#461051

Thank you Nigel,

Please, I have antother question.
I have field Yacht size (wpcf-yacht-size) Could you give me a right syntax how to display this field on the front end without any additional plugin (egg.layouts).

Thank you

Regards

#461063

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Renato

If you are working in the PHP templates directly you can use the function types_render_field, but if you are using shortcodes in posts, templates or views you would use the types shortcode.

I don't know what field type your Yacht size field is, but you can see a complete reference for the different field types and how to render them here: https://toolset.com/documentation/customizing-sites-using-php/functions/

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.