WordPress.org

Ready to get started?Download WordPress

Forums

GC Testimonials
[resolved] Post meta data empty on frontend (gct_get_post_custom doesn't accept params) (5 posts)

  1. Daniele Raimondi
    Member
    Posted 3 months ago #

    Symptom: In some situation, gc Testimonials widget is unable to retrieve and display post meta like client_name, company_name etc.

    Cause: Function gct_get_post_custom() tries to get custom post metas for the post, using the global $post variable, but the global $post can contain data coming from any post type, depending on the contest, and not only from GC_testimonial posts.
    This function it's called everywhere passing in the post ID as parameter but it doesn't accept parameters. So, when the global $post contain something else than a GC_testimonial post, the function can't retrieve custom meta as client_name, company_name etc etc.

    Solution: To fix this issue, I've just added a param in the function definition and then passed it to get_post_custom. Just go to the last function in testimonials.php and substitute it with the following:

    function gct_get_post_custom($post_id) {
    	global $post;
    
    	//eventually get post id from the current query
    	if (empty($post_id))
    		$post_id = $post->ID;
    
    	$custom = get_post_custom($post_id);
    	$fields = array(
    		'client_name',
    		'client_photo',
    		'company_name',
    		'company_website',
    		'email',
    	);
    	foreach ( $fields as $field ) {
    		if ( ! isset( $custom[ $field ][ 0 ] ) )
    			$custom[ $field ][ 0 ] = '';
    	}
    
    	return $custom;
    }

    https://wordpress.org/plugins/gc-testimonials/

  2. Chris Dillon
    Member
    Posted 3 months ago #

    Symptom: In some situation, gc Testimonials widget is unable to retrieve and display post meta like client_name, company_name etc.

    Can you identify the situations in which you have experienced that symptom so as not to through others into a panic?

    Cause: Function gct_get_post_custom()

    There is no function with that name in GC Testimonials.

    tries to get custom post metas for the post, using the global $post variable, but the global $post can contain data coming from any post type, depending on the context, and not only from GC_testimonial posts

    This is misleading and irrelevant. The global $post is either (a) the current post in The Loop (front end), or (b) the current post, of any type, being edited or displayed (back end).

    There are exactly four uses of the global $post in testimonials.php:
    1. to check for shortcodes when scripts and styles are enqueued for the page (front end)
    2. to add the meta columns for each testimonial in the table of testimonials (back end)
    3. to get the meta when editing a testimonial (back end)
    4. to save the meta when editing a testimonial (back end)
    These are all valid and tested.

    The widget properly uses WP_Query to fetch testimonials without touching the global $post.

    when the global $post contain something else than a GC_testimonial post, the function can't retrieve custom meta

    What other possible causes have you ruled out?

    I do not see how the error situation that you described can occur within the plugin; therefore, I do not see how your solution is necessary.

  3. Daniele Raimondi
    Member
    Posted 3 months ago #

    I'm so sorry! I've installed the plugin downloading it from github, without realizing that the version I was using is a fork of this plugin.
    You can imagine my surprise when I read "There is no function with that name in GC Testimonials." :D

    I'm now using the plugin from WP repository and I confirm that it works like a charm.

    Thanks, Daniele.

  4. Chris Dillon
    Member
    Posted 3 months ago #

    No worries :) I actually enjoyed digging into it deeper.

    If forking hasn't left a bad taste, I invite you to try my fork of GCT, Strong Testimonials.

  5. Daniele Raimondi
    Member
    Posted 3 months ago #

    Great!
    I'm giving a quick look to the code of Strong Testimonials and I guess I can't deactivate "GT" and activate "Strong", mantaining testimonials data, but I'm really going to try your plugin soon.

    Thanks again.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.