How do I access a wordpress table from a custom plugin

My project is a historical photographic archive and using NextGEN Gallery is a more elegant solution than my attempt using Pods. I have a search plugin customised to be used with Pods.

I want to know how to target the wp_ngg_pictures table using php so I can replicate the code below without using the Pods plugin and be able to search the fields.

$thePod = pods($tableName); // $tableName is a string variable set to wp_ngg_pictures
$params = array( 'orderby' => 't.name ASC', 'limit' => -1, 'where' => " t.description LIKE '%$searchTerm%' || t.alttext LIKE '%$searchTerm'");
$thePod->find($params);

Related posts

Leave a Reply

1 comment

  1. You can try something like this to access custom table in your plugin.

    global $wpdb;    
    $wpdb->custom_table_name = $tableprefix.'custom_table_name';
    

    OR

    $data = $wpdb->get_row("SELECT field name FROM $wpdb->custom_table_name, ARRAY_A");
    echo $data;
    

    word press standard way to get row is like this

    $wpdb->get_row('query', output_type, row_offset);
    

    if you have multiple rows than use this

    $wpdb->get_results( 'query', output_type );