• Resolved gmex1292

    (@gmex1292)


    I have a custom template that I have been using and it was working fine. Everything was working fine with previous versions of the plugin. I have updated the PDB plugin to the latest versions and still working fine. Below is what was working for Link field:

    
    		  if ( $this->field->name == 'my_url' ) {
    		  $myURL = $this->field->get_value('my_url');
    		  }
    
    echo "$myURL"
    
    

    This all worked fine. I want to add a new field (checkbox).

    I went into the backend and added a new field (checkbox) type field. I then went into the Manage List Columns area, and the interface is different. I dragged my new field into the List Columns area at the end because I want to be able to access it via code. I could not see anywhere to “save” so I assumed is just saves automatically.

    Now, the last 2 fields in the List Columns (link and checkbox) now don’t work via code:

    
    		  if ( $this->field->name == 'my_url' ) {
    		  $myURL = $this->field->get_value('my_url');
    		  }
    
    echo "$myURL"
    
    		  if ( $this->field->name() == 'my_checkbox' ) {
    		  $myCheckbox = $this->field->get_value_display('my_checkbox');
    		  }
    
    echo "$myURL $myCheckbox"
    

    I’m assuming that there is something in the PDB interface that I did wrong, but with the new interface I can’t figure it out. The old interface had a “display_column” check box that would let my code access it.

    Any help would be appreciated!

    • This topic was modified 4 years, 11 months ago by gmex1292.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author xnau webdesign

    (@xnau)

    The correct code to use for getting the field value is something like this:

    if ( $this->field->name() === 'my_url' ) {
       $myURL = $this->field->get_value();
    }

    the get_value method doesn’t take an argument.

    Thread Starter gmex1292

    (@gmex1292)

    Unfortunately that did not work for either one. I changed it to:

    
    		  if ( $this->field->name() === 'my_url' ) {
    		  $myURL = $this->field->get_value();
    		  }
    
    echo "$myURL"
    
    		  if ( $this->field->name() === 'my_checkbox' ) {
    		  $myCheckbox = $this->field->get_value_display('my_checkbox');
    		  }
    
    echo "$myURL $myCheckbox"
    
    Thread Starter gmex1292

    (@gmex1292)

    If this helps, I have several other fields that I changed to your syntax and they all work fine. It’s only the 2 fields that I moved in the “Manage List Columns” that don’t work.

    The exact recreation of what I did was, add the new checkbox field to the “Manage Database Fields” page. I did not reorder anything here. It just appended at the end of the list of fields. Next, I went to the “Manage List Columns” page, dragged my new checkbox field from the “Public List Column Setup” into the “List Columns”.

    When I dragged it attempting to drop at the very end of the list, (at this point the URL field was at the end) it moved the URL field in between all the other fields. The checkbox field was now at the end, then I dragged the URL field so that it was before the checkbox field.

    I hope that makes sense!

    Plugin Author xnau webdesign

    (@xnau)

    Are the list columns displaying as expected? Is it only in the code that you see this problem?

    By the way, the field get_value_display also does not take an argument. You don’t need to tell it what field to show because you’re already using the field object to call the method.

    Thread Starter gmex1292

    (@gmex1292)

    I created a new blank page and put the [pdb_list] shortcode in, and all the list columns display correctly, including the two I’m having trouble with, which are at the end which is where I expect to see them. I corrected all of the other instances of get_value_display per your recommendation. Still not working (in code I guess).

    Thread Starter gmex1292

    (@gmex1292)

    Ok here is an interesting update…

    I went into the Manage List Columns area, in the Public List Setup, I dragged my new checkbox field out of the “List Columns” back into the “Available Fields” and it dropped into that area. I refreshed my page and the LINK field now works like it was before.

    if ( $this->field->name() === 'my_url' ) {
    $myURL = $this->field->get_value();
    }

    The interesting part is, I went back into the Manage List Columns area, didn’t touch anything and the new field that I moved up into the “Available Fields” area, is now back in the “List Columns” area in a DIFFERENT spot and I didn’t touch it! Although the new field (checkbox) is there now in the List Columns area after it seemingly moved back on it’s own, it doesn’t work via code like before.

    if ( $this->field->name() === 'my_checkbox' ) {
    $myCheckbox = $this->field->get_value_display();
    }

    I checked by blank page with [pdb_list] and the columns all show, including the new one (in the different order now). But still can’t get it via code (it’s the only field that won’t work!).

    I have a before and after shot of the wp_participants_database_fields table, and the only thing that changed was the display_column now has a different order – which is probably expected.

    • This reply was modified 4 years, 11 months ago by gmex1292.
    Thread Starter gmex1292

    (@gmex1292)

    I figured it out and it was my fault all along. I was using the “Title” not the “Name” of the field. The problem was that I used dashes in the field name (ie my-field) but when the field was created, it replaced the dashes with underscores (my_field) and I didn’t realize it. It was the only field that I created with dashes. It works fine now.

    Thank you so much for the help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Dragged a new field into List Columns, now it can’t get value’ is closed to new replies.