Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Geo-mashup errors on error_log WordPress

  • SOLVED

In error_log, I receive this multiple times each time a page loads.
[07-Jul-2018 17:30:49 UTC] WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND p.post_status='publish'' at line 6 for query SELECT count(*) FROM wp_posts p
INNER JOIN wp_term_relationships tr ON tr.object_id = p.ID
INNER JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN wp_geo_mashup_location_relationships gmlr ON gmlr.object_id = p.ID AND gmlr.object_name = 'post'
WHERE tt.term_id =
AND p.post_status='publish' made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/hestia-child/front-page.php'), get_footer, locate_template, load_template, require_once('/themes/hestia-child/footer.php'), do_action('hestia_do_footer_child'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, hestia_the_footer_content_child, dynamic_sidebar, call_user_func_array, WP_Widget->display_callback, WP_Widget_Categories->widget, wp_dropdown_categories, walk_category_dropdown_tree, call_user_func_array, Walker->walk, Walker->display_element, call_user_func_array, Walker_CategoryDropdown->start_el, apply_filters('list_cats'), WP_Hook->apply_filters, call_user_func_array, GeoMashup::list_cats, GeoMashupDB::category_located_post_count



I think it leads to a section of GeoMashup's "geo-mashup-db.php" (copied below) and I've read some things about upper/lower case mismatches between ID/id thta can cause this, but I can't seem to find any instances of that. Any help or suggestions would be great.
* Get the number of located posts in a category.
*
* @since 1.2
*
* @param id $category_id
* @return int
*/
public static function category_located_post_count( $category_id ) {
global $wpdb;

$select_string = "SELECT count(*) FROM {$wpdb->posts} p
INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.ID
INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN {$wpdb->prefix}geo_mashup_location_relationships gmlr ON gmlr.object_id = p.ID AND gmlr.object_name = 'post'
WHERE tt.term_id = " . esc_sql( $category_id ) ."
AND p.post_status='publish'";
return $wpdb->get_var( $select_string );
}

/**
* Get categories that contain located objects.
*
* Not sufficient - probably want parent categories.
*
* @return array Located category id, name, slug, description, and parent id
*/
private static function get_located_categories() {
global $wpdb;

$select_string = "SELECT DISTINCT t.term_id, t.name, t.slug, tt.description, tt.parent
FROM {$wpdb->prefix}geo_mashup_location_relationships gmlr
INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id = gmlr.object_id
INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
WHERE tt.taxonomy='category'
ORDER BY t.slug ASC";
return $wpdb->get_results( $select_string );
}

Answers (4)

2018-07-07

Arnav Joy answers:

This error is there in plugin files ??


User180104 comments:

I honestly don't know now.


User180104 comments:

OK, yes, I've confirmed it is in the plugin.


Arnav Joy comments:

can you send me access to your site ?
my email is : [email protected]
I will need admin/ftp/db access


User180104 comments:

I'm sorry, I know that would make it easier, but I cannot give out those credentials.

2018-07-07

Cesar Contreras answers:

You can try to concatenate the sentence in this way...

public static function category_located_post_count( $category_id ) {
global $wpdb;

$select_string = "SELECT count(*) FROM {$wpdb->posts} p ";
$select_string .= "INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.ID ";
$select_string .= "INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id ";
$select_string .= "INNER JOIN {$wpdb->prefix}geo_mashup_location_relationships gmlr ON gmlr.object_id = p.ID AND gmlr.object_name = 'post' ";
$select_string .= "WHERE tt.term_id = " . esc_sql( $category_id ) . " AND p.post_status='publish'";
return $wpdb->get_var( $select_string );
}


User180104 comments:

Thank you, but it did not seem to effect any of the errors.

2018-07-08

Mohamed Ahmed answers:

Hello,

If you look at the MySQL error message you will know the SQL query error is related to GeoMashupDB::category_located_post_count() function.
and the problem is after the WHERE tt.term_id =:

WHERE tt.term_id =
AND p.post_status='publish'

Because the term ID was empty and must send a valid $category_id
E.g. GeoMashupDB::category_located_post_count( 123 )

you can edit that function, by adding the following before the global $wpdb; line to be the function like that:


* Get the number of located posts in a category.
*
* @since 1.2
*
* @param id $category_id
* @return int
*/
public static function category_located_post_count( $category_id ) {

// Make sure `$category_id` is a valid integer value.
if ( ! is_numeric( $category_id ) || ! $category_id ) {
return false;
}

global $wpdb;
$select_string = "SELECT count(*) FROM {$wpdb->posts} p
INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.ID
INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN {$wpdb->prefix}geo_mashup_location_relationships gmlr ON gmlr.object_id = p.ID AND gmlr.object_name = 'post'
WHERE tt.term_id = " . esc_sql( $category_id ) ."
AND p.post_status='publish'";
return $wpdb->get_var( $select_string );
}

/**
* Get categories that contain located objects.
*
* Not sufficient - probably want parent categories.
*
* @return array Located category id, name, slug, description, and parent id
*/
private static function get_located_categories() {
global $wpdb;

$select_string = "SELECT DISTINCT t.term_id, t.name, t.slug, tt.description, tt.parent
FROM {$wpdb->prefix}geo_mashup_location_relationships gmlr
INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id = gmlr.object_id
INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
WHERE tt.taxonomy='category'
ORDER BY t.slug ASC";
return $wpdb->get_results( $select_string );
}


User180104 comments:

Thank you for the explanation, and it makes sense, but unfortunately this code did not change anything. I a still getting the same errors.


Mohamed Ahmed comments:

Could you send me the error after you have updated the code?


Mohamed Ahmed comments:

The plugin is updated and Last updated from 22 hours only.
Could you check it now?

2018-07-10

Dylan Kuhn answers:

It may just be that this old Geo Mashup feature won't work with your site. If you uncheck Settings / Geo Mashup / Overall / Obscure Settings / Add Category Links and save the settings it should go away.


User180104 comments:

!! You were correct. This checkbox seemed to be "stuck". Removing the plugin completely and re-installing allowed me to uncheck it & save correctly. Now the errors have cleared.

* Please, can you tell me if this plugin will be continued development? I find it VERY useful and I am very interested in supporting any efforts to continue with it.

Thank you!


User180104 comments:

I see the plugin was closed today, just now.
I suppose that means it's over for good?


Dylan Kuhn comments:

I expect Geo Mashup to be re-opened on WordPress.org, but I'm not sure how long it will take. It was flagged for some old code that isn't up to snuff with current standards. I plan to fix the issues and submit it for review.

Long term I hope to at least keep the plugin running smoothly, which I've managed since 2005. New features are rare, but more likely if sites buy business plan subscriptions.


User180104 comments:

Thank you so much! Your reply is one of the best things I've read in a while. (relief!). A lot of a new site relies on it.

To help show some love, I just purchased a year's business plan.
If you can make it play nicely with PHP7, I will gladly & happily buy a lifetime license too!
Thanks again.