if ! empty $groupvariable not working
- This topic has 3 replies, 2 voices, and was last updated 8 years, 10 months ago by
jonwatson87.
-
AuthorPosts
-
June 16, 2016 at 7:18 AM #3458
jonwatson87
ParticipantHey guys!
I've got the same issue I had a few months ago. I'm not sure we ever really fixed it.
Querying if a group is empty or not doesn't seem to work as described in the docs.
The code I'm using:
// Coverage Shortcode function epi_publication_coverage_shortcode() { ob_start(); // Press Coverage $coveragegroup = rwmb_meta( 'epi_pubcoverage' ); if ( ! empty( $coveragegroup ) ) { echo 'NOT EMPTY'; } else { } return ob_get_clean(); } add_shortcode('show_publication_coverage','epi_publication_coverage_shortcode');
Displays "NOT EMPTY" on all posts, even if they don't have any coverage.
Is the group saving a blank field somewhere? Should I be querying on a checkbox or something instead?
Code used to register group:
// Add Coverage Meta Boxes $meta_boxes[] = array( 'title' => 'Press Coverage', 'post_types' => array('post', 'report', 'analysis', 'guest-blog'), 'context' => 'normal', 'priority' => 'low', 'desc' => '(drag to reorder)', 'fields' => array( array( 'id' => 'epi_pubcoverage', 'type' => 'group', 'clone' => true, 'sort_clone' => true, 'fields' => array( array( 'name' => 'Title', 'id' => $prefix . 'pubcoveragedesc', 'type' => 'text', 'desc' => 'Title or description for link', ), array( 'name' => 'URL', 'id' => $prefix . 'pubcoverageurl', 'type' => 'text', 'desc' => 'Link to coverage', ), array( 'name' => 'Date', 'id' => $prefix . 'pubcoveragedate', 'type' => 'date', 'desc' => 'Date of event coverage', ), ), ), ), ); return $meta_boxes;
And all plugins have been updated to latest versions.
June 16, 2016 at 7:25 AM #3459jonwatson87
ParticipantConfirmed. The default white space is somehow being saved as a populated field when the post is updated.
I renamed the group and the if !empty worked. I updated a post, leaving these fields blank, and it stopped working.
Even if these fields are left blank, the empty fields still register as being content and if !empty returns true.
I'm gonna use a checkbox to hide this section for now and query that instead.
June 16, 2016 at 9:32 PM #3466Anh Tran
KeymasterI understand. I thought I did this in the previous version but looks like not. I will fix it so
empty
work.Thanks for noticing the bug.
June 17, 2016 at 12:09 AM #3469jonwatson87
ParticipantNo worries, Anh! Hope you figure it out 🙂 Not a problem to bypass it with a checkbox as long as people are aware of the issue.
-
AuthorPosts
- The topic ‘if ! empty $groupvariable not working’ is closed to new replies.