WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Fatal error: Unsupported operand types - using $wpdb (4 posts)

  1. AronMS
    Member
    Posted 1 year ago #

    I'm writing a custome plugin with custome database, but using the $wpdb class. For pagination I am trying to return a count from the database then perform a calculation on the results, but there is a problem with my code, which is causing this error:

    Fatal error: Unsupported operand types in ... on line 53

    here is the code:

    $pages_query = $wpdb->prepare("SELECT COUNT FROM Table WHERE FullName LIKE '%%%s%%';", $NameSearch . '%');
    $pages = ceil($wpdb->get_results($pages_query, 0) / $per_page);

    How can I fix this ?

  2. cimeran
    Member
    Posted 1 year ago #

    Try...

    $pages_query = $wpdb->prepare("SELECT COUNT(*) FROM Table WHERE FullName LIKE '%s';", '%'.$NameSearch.'%');
    $pages = ceil($wpdb->get_results($pages_query, 0) / $per_page);
  3. AronMS
    Member
    Posted 1 year ago #

    Thanks for your reply @cimeran
    Tried your code but I got exactly the same error :(
    I think I may need to try another method.

  4. AronMS
    Member
    Posted 1 year ago #

    Ah ha! Eventually found this article form Turmsegler.NET on Separate DB connection for WordPress plugins, which had solution for anyone wanting to develop a custom plugin with a custom database.

    http://turmsegler.net/20080129/separate-db-connection-for-wordpress-plugins/

Topic Closed

This topic has been closed to new replies.

About this Topic