0

I'm running WP Job Manager plugin which is designed to allow its custom post type fields to be altered within a theme or plugin via custom filters.

I have added my own custom fields (example) and the theme I'm using has also added its own fields added.

I've updated my fields and now I need to loop through all the entries, get $key / $value pairs, and update those values if needed. The problem is get_post_meta() is only returning a couple entries. Consider the following code to be used in the bulk update loop:

public function save_to_wordpress(array $page_elements) {
        $post_id = $this->get_post_id_by_title($page_elements['title']);

        if($post_id === false) {
            $post_id = wp_insert_post(
                    array(
                        'comment_status' => 'closed',
                        'ping_status' => 'closed',
                        'post_author' => get_user_by('email', 'email@domain.com'),
                        'post_title' => $page_elements['title'],
                        'post_status' => 'draft',
                        'post_type' => 'job_listing',
                        'post_content' => $page_elements['description']
                    )
            );
        } else {
           // update job_listing meta data here
        print "Post with ID $post_id already exists.<br />";
        $listing = get_post_custom($post_id);

        var_dump($listing);
    }
}

The output of the var_dump is only the following, which it should have about 50 or so $key / $value pairs:

array (size=2)
  '_filled' => 
    array (size=1)
      0 => string '0' (length=1)
  '_featured' => 
    array (size=1)
      0 => string '0' (length=1)

How do I approach getting these $key / $value pairs for update when different plugins and themes modify the meta fields for this custom post type at different times?

  • Are you confident you are getting the right post ID? Storage might be abstracted into different post types and stuff. – Rarst Aug 31 '15 at 14:58
  • I double checked. Yes it was the right ID, but here is an update. Programmatically, these are saved as drafts. I actually must go into the page edit area and hit the save draft button. Once I do that, the fields become available with the above code. Any thoughts on why that would happen? – user658182 Aug 31 '15 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.