Menu

#8 Custom fields give DB error when advanced form is default

open
nobody
5
2004-12-14
2004-12-14
No

In admin, go to Options -> Writing. Select "Advanced controls" and
click "Update Options". Now click "Write" to create a new post.
You'll get this error underneath "Custom fields":

SQL/DB Error -- [ERROR: invalid input syntax for integer: "" ]
Array
(
[0] => Array
(
[file] => /Users/paul/Creative efforts/Web/innig/music/
inthehands/wp-includes/wp-db.php
[line] => 198
[function] => print_error
[class] => wpdb
[type] => ->
[args] => Array
(
)

)

[1] => Array
(
[file] => /Users/paul/Creative efforts/Web/innig/music/
inthehands/wp-includes/wp-db.php
[line] => 387
[function] => query
[class] => wpdb
[type] => ->
[args] => Array
(
[0] =>
SELECT meta_key, meta_value, meta_id, post_id
FROM ith_postmeta
WHERE post_id = ''
ORDER BY meta_key,meta_id
)

)

[2] => Array
(
[file] => /Users/paul/Creative efforts/Web/innig/music/
inthehands/wp-admin/admin-functions.php
[line] => 212
[function] => get_results
[class] => wpdb
[type] => ->
[args] => Array
(
[0] =>
SELECT meta_key, meta_value, meta_id, post_id
FROM ith_postmeta
WHERE post_id = ''
ORDER BY meta_key,meta_id
[1] => ARRAY_A
)

)

[3] => Array
(
[file] => /Users/paul/Creative efforts/Web/innig/music/
inthehands/wp-admin/edit-form-advanced.php
[line] => 179
[function] => has_meta
[args] => Array
(
[0] =>
)

)

[4] => Array
(
[file] => /Users/paul/Creative efforts/Web/innig/music/
inthehands/wp-admin/post.php
[line] => 748
[args] => Array
(
[0] => /Users/paul/Creative efforts/Web/innig/
music/inthehands/wp-admin/edit-form-advanced.php
)

[function] => include
)

)

Here is a fix:

In wp-admin/admin-functions.php, change the has_meta function
from this:

function has_meta($postid) {
global $wpdb, $tablepostmeta;

return $wpdb->get_results("
SELECT meta_key, meta_value, meta_id, post_id
FROM $tablepostmeta
WHERE post_id = '$postid'
ORDER BY meta_key,meta_id",ARRAY_A);

}

To this:

function has_meta($postid) {
global $wpdb, $tablepostmeta;

if(!$postid) return false;

return $wpdb->get_results("
SELECT meta_key, meta_value, meta_id, post_id
FROM $tablepostmeta
WHERE post_id = '$postid'
ORDER BY meta_key,meta_id",ARRAY_A);

}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.