Closed galloppinggryphon closed 4 years ago
Issue-Label Bot is automatically applying the label Type: Bug
to this issue, with a confidence of 0.95. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!
Links: app homepage, dashboard and code for this bot.
'where' => "entry_type.meta_value = 'organization'" // <<< This produces the error
This would work if entry_type
is an existing field. Is that te case?
Also, that part should not be wrapped in quotes. But if you do you'll need to wrap each traversal name individually, not as a whole.
entry_type
is indeed an existing field and the clause filters data the way I would expect. With the workaround, I remove the error too.
The code is a PHP array `[ 'where' => "entry_type.meta_value = 'organization'" ] so the quotes are legit. I'm following instructions from https://pods.io/docs/code/pods/find/
Anyway, this is the code that triggers the error, 'Empty needle' (in classes/PodsData.php on line 3058
):
strpos( $traverse_recurse['params']->table, $wpdb->prefix )
The value of the needle, $wpdb->prefix
, is empty or zero-length string (''
), causing PHP to lose its head. The simple fix of checking if $wpdb->prefix is empty appears to have solved the issue.
WP is running on PHP 7.2. I wrote a strpos test on PHP 7.3 and 7.4, but it was just as unhappy about an empty needle. Funnily enough, it had no problems with accepting null or an undeclared variable. Aaah, PHP.
Hi @galloppinggryphon
That is strange.. $wpdb->prefix
should never be empty, or did you omit the prefix in general for this installation?
Hi @galloppinggryphon
I've created a patch that should fix your issue. See https://github.com/pods-framework/pods/pull/5816 If you could confirm this fix that would be great!
Cheers, Jory
PHP Warning: strpos(): Empty needle in /home/***/wp/wp-content/plugins/pods/classes/PodsData.php on line 3058
On this line, traverse_recurse() checks if the selected table name is a WP table or not by testing for the presence of the WP table prefix at the beginning of the string. In my setup, the table prefix is empty, leading to the error above.
To Reproduce
The problem occurs when running a custom WHERE clause pulling a custom field:
The code is located in a theme template file. As far as I can tell the WHERE clause works; it produces the right output.
Expected behavior Pods should be flexible enough to allow an empty prefix or state clearly in the setup documentation that this does not work, and then produce a clear error message in the Dashboard.
Possible Workaround Changing line 3058 to check if the prefix is empty bypasses the problem, but I don't know that it's enough to fix it completely or if Pods relies on the presence of a prefix throughout the code.
Pods Version
2.7.21
WordPress Environment