0

I am building a plugin in WordPress and $wpdb queries works on local, but when I upload the code to the server it doesn't work.

Here is the code that I'm using:

<?php 

global $wpdb;

$resultado = $wpdb->get_results(
    $wpdb->prepare(
        "SELECT meta_value FROM wp_postmeta WHERE meta_key='keywords'",
        OBJECT
    )
);

$keywords = implode(',', array_column($resultado, "meta_value"));

?>
cabrerahector
  • 3,653
  • 4
  • 16
  • 27
  • Two observations: 1) If you're not passing variables to the query you don't really need to use the [prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/) method at all; and 2) `OBJECT` has to be passed to [get_results()](https://developer.wordpress.org/reference/classes/wpdb/get_results/), not to the `prepare()` method. – cabrerahector Sep 28 '20 at 19:12
  • are you sure table name same on server `wp_postmeta` but sometime prefix might be different. Try something like `global $wpdb, $table_prefix;$table = $table_prefix . 'postmeta';` – Avinash Dalvi Sep 28 '20 at 19:13
  • now i tried with global ` $wpdb, $table_prefix;$table = $table_prefix . 'postmeta';` and change the query to ` $resultado = $wpdb->get_results("SELECT meta_value FROM $table WHERE meta_key='keywords'", OBJECT );` and this works on local but still not working on server – Nicolas Reyes Gomez Sep 28 '20 at 19:32

0 Answers0