Register custom table for WP to use in a plugin

That’s not what the $tables variable does, and there is no such thing as a registered custom table. These variables are an internal API not intended for plugin/theme developer use. The $wpdb->mytable pattern itself is just something someone did because they wanted to avoid prefixing manually that caught on in early WordPress articles. The reason … Read more

How to left join meta in queries [closed]

One possible solutions is use Queries in the joins instead of tables. so the query would look something like //read products with thumbnail and sku SELECT products.*, skus.sku, thumbs.thumbnail FROM `wp_posts` as products LEFT JOIN ( SELECT posts2.ID, pm1.meta_value as sku FROM `wp_posts` as posts2 LEFT JOIN `sf_postmeta` as pm1 ON posts2.ID = pm1.post_id WHERE … Read more

Compare transient data with a meta box value

I would do the following: Create WP-Cron task (or just use daily wp_scheduled_delete one to tag along) and hook your function to it. In that function: fetch XML file; fetch all posts with meta_weight set, using get_posts(); loop through posts and save comparison result in another meta field for each.

Custom $wpdb returns unexpected time based results

This may be your problem: $wpdb->terms.slug = ‘another-sample’ OR $wpdb->terms.slug = ‘sample’ AND //the date logic doesn’t seem to qork quite right $wpdb->posts.post_date > DATE_SUB( NOW(), INTERVAL 7 DAY)”; Your OR operator might be confusing the query. Try using parentheses: ($wpdb->terms.slug = ‘another-sample’ OR $wpdb->terms.slug = ‘sample’) AND //the date logic doesn’t seem to qork … Read more

Custom SQL query ORDER BY term_order

In your case you are referring ORDER BY {$wpdb->terms}.term_order and as default in wordpress wp_terms table don’t have this column the term_order column resides in the wp_term_relationships table and you are referring wp_terms table to ORDER BY this column which is not is present in that table instead of this you have to do something … Read more

Create new database through static page code

DBDelta is extremely picky— to the point of being maddening sometimes. From the Codex: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym … Read more

how to get db values without using an loop with wpdb->get_results()

You want get_row. Per the Codex: Get all the information about Link 10. $mylink = $wpdb->get_row(“SELECT * FROM $wpdb->links WHERE link_id = 10”); The properties of the $mylink object are the column names of the result from the SQL query (in this example all the columns from the $wpdb->links table, but you could also query … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)