• Hello

    I am trying to update a custom field with some data that I collect in the CFDB plugin. I can see all my data correctly if I use die() before the actual update_post_meta call. Here’s my code:

    add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 );
    
    function modify_post_title( $data , $postarr )
    {
      if($data['post_type'] == 'pets') {
      	// Get all the email addresses associated with this pet that has sponsored
      	$graciousSponsors = do_shortcode('[cfdb-value form="Untitled" show="Extra2" filter="PetName='.$data['post_title'].'"]');
      	//die ($graciousSponsors." , ".$postarr['ID']." , ".join(", ",explode(", ", $graciousSponsors)));
        // Now set the custom field's value to the list of email addresses
        update_post_meta ($postarr['ID'], 'sponsor_emails', join(", ",explode(", ", $graciousSponsors)), false);
      }
      return $data;
    }

    the die() call shows me all of my information correctly. ANy help would be appreciated. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter RiaanPie

    (@riaanpie)

    Any help here would be appreciated. I am sure the code is right.. but I just end up on a blank page. :/

    with some data that I collect in the CFDB plugin.

    Which plugin is that? You might want to ask on the forum for that plugin?

    Thread Starter RiaanPie

    (@riaanpie)

    This plugin: https://cfdbplugin.com/

    But that’s not where my problem lies.. it’s with an internal WordPress function: wp_insert_post_data.

    Okay, I’ll move this thread to the “Hacks” forum – the regulars there should be able to help you with this kind of question ??

    Thread Starter RiaanPie

    (@riaanpie)

    haha.. ?? thanks, I appreciate that.

    Moderator bcworkz

    (@bcworkz)

    The white screen indicates a PHP error of some sort. To find out what that is, define WP_DEBUG as true on your wp-config.php file. Now when a post is inserted, you’ll see error messages on the white screen, telling you what and where the problem is.

    Thread Starter RiaanPie

    (@riaanpie)

    Thanks for your response, bcworkz. I turned that on as well as added error_reporting(E_ALL) but I still just see a blank screen.

    error_reporting(e_all);
    add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 );
    
    function modify_post_title( $data , $postarr )
    {
      if($data['post_type'] == 'pets') {
      	// Get all the email addresses associated with this pet that has sponsored
      	$graciousSponsors = do_shortcode('[cfdb-value form="Untitled" show="Extra2" filter="PetName='.$postarr['post_title'].'"]');
      	//die ($graciousSponsors." , ".$postarr['ID']." , ".join(", ",explode(", ", $graciousSponsors)));
        // Now set the custom field's value to the list of email addresses
        $foobar = join(", ",explode(", ", $graciousSponsors));
        update_post_meta ($postarr['ID'], 'sponsor_emails', $foobar);
      }
      return $data;
    }
    Moderator bcworkz

    (@bcworkz)

    FYI, PHP is case sensitive, E_ALL != e_all. It doesn’t matter here anyway, WP_DEBUG sets the error reporting for you. You could also check your error logs for any error messages, just in case the usual error output to the browser was circumvented for some reason.

    The snippet you posted does not contain any errors, it runs fine on my installation (once I changed ‘pets’ to one of my CPTs and ‘[cfdb-value]’ to one of my shortcodes). Thus the problem is either in the shortcode handler, or there’s a plugin or theme conflict.

    Does the shortcode work OK when placed in post content as usual? I’m guessing it does, so in that case there must be a conflict. Deactivate all of your plugins. If you still have a problem, your theme is creating a conflict, switch to a twentysomething theme to confirm. If a problem plugin is indicated, reactivate each plugin, one at a time. When the problem returns, the last activated plugin is the culprit.

    Thread Starter RiaanPie

    (@riaanpie)

    Thanks for the detailed response, bcworkz. I will try that and revert with feedback. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘wp_insert_post_data won't update meta and shows white screen’ is closed to new replies.