Skip Navigation

[Closed] Cannot get custom field data after custom shortcode

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2284969
Screenshot 2022-02-06 at 6.08.56 PM.png
Screenshot 2022-02-06 at 5.26.14 PM.png

Dear Sir/Madam,

I don't find the reason why my shortcode affect the custom field data display in View, I do execute the wp_reset_postdata(), it should resume the post record.

All custom field will return empty value if I paste the shortcode before them.

[membership_pay numbeds="[types field='actual-bednum' format='FIELD_VALUE'][/types]" membership_id="[types field='member-id'][/types]" expiry="[types field='expiry-date' output='raw'][/types]"]

shortcode script in functions.php

function ebz_membership_pay($atts) {
    $args = array(
        'post_type'         => 'membership-group',
        'post_status'       => 'publish',
        'posts_per_page'    => -1,
    );

    $the_query = new WP_Query($args);
    $num = intval($atts['numbeds']);

    if ( $the_query->have_posts() ) {
        $range = [];
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
        
            $membership_cat = get_post_meta(get_the_ID(), 'wpcf-membership-category', true);
            $membership_fee = get_post_meta(get_the_ID(), 'wpcf-membership-fee', true);
            $product_id = get_post_meta(get_the_ID(), 'wpcf-membership-product-id', true);
            $values = explode("_", $membership_cat);
            array_push($range, ["min"=>$values[1], "max"=>$values[2], "fee"=>$membership_fee, "sku"=>$membership_cat]);
        }
    }
    wp_reset_postdata();
    if (intval($atts['expiry']) < (time() + 180 * 24 * 60 * 60)) {
        foreach ($range as $key=>$value) {
            if (in_array($num, range($value['min'], $value['max']), true)) {
                $rtn = sprintf("<a target='_blank' href='<em><u>hidden link</u></em> class='btn btn-success btn-xs'>繳交會費</button></a>", $atts['membership_id'], $product_id);
            }
        }
    }
    return $rtn;
    
}
add_shortcode('membership_pay', 'ebz_membership_pay');

The $rtn can be correctly returned html

#2285455

Hello,

It is a custom codes problem, there might be some PHP errors in your website, please try to get the PHP debug logs:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#php-debugging

If you need more assistance for it, please provide a test site with the same problem, also point out the problem page URLs, and where I can edit your custom PHP codes.

The topic ‘[Closed] Cannot get custom field data after custom shortcode’ is closed to new replies.