0

So I have a piece of code written and it worked before, hasn't been edited hasn't been changed, no updates on the WP DB no updates on any plugin on WP and it's suddenly not working correctly.

This is the code:

  $column1   = "member_name";
  $column2   = "memberID";
  $meta_key  = "field_dsfsd332dsfd";
  $result    = $newdb->get_results("SELECT ".$column1.",".$column2."  FROM members LIMIT 1");

        if(isset($_POST['submit'])){
        foreach ($result as $c) {
            $postargs = array(
                'post_title'   => $c->member_name,
                'post_status'  => 'draft',
                'post_type'    => 'bedrijf'
            );

            $thisid = wp_insert_post ( $postargs, true);

            if ( is_wp_error($thisid) ) {
                return get_error_codes();
            } else {  
                update_field( $meta_key, $c->memberID, $thisid);
            }
          }
        }

So what happens is that the code inserts into my Custom Post type from another DB, as a result you'll see a new Post there and a filled in title+custom post field. What goes wrong is that it inserts it in the Database of WP (as it shows on view posts as All(3) if for example 3 are inserted) but it does not show up as editable in WP-Admin at all!

Although when I manually add a post to the Custom Post type by for example clicking "Add New" it shows it perfectly fine as well as it changes into All(4) but with only one shown(the one I made manually).

Why is this happening?

MAJOR EDIT: So I found out changing it to draft causes the issue to not show up AT ALL. I have no idea why this is so and would appreciate explanation but for now it's working with Publish.

EDIT2: So I solved it by writing draft with capitol D so Draft only works..(Strange it should work without either).

  • Just to be sure - you're not filtering on "Published", are you? – kraftner Mar 19 '14 at 10:23
  • No I'm not, I'm trying to click on All(4) and what happens is that it says that it can't find any results, but they're in the DB? I even tried a fresh reinstall of WP and DB but have yet to come up with a solution. – David H Mar 19 '14 at 10:25
  • 1
    I would love to but I can't accept it until two days, i'll add it as an answer though. – David H Mar 19 '14 at 10:58
1

It wasn't working because at public status draft/publish were written without a capitol so it has to be 'post_status' => 'Draft' or 'post_status' => 'Publish'

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.