How to correctly call custom field dates into a posts_where filter using SQL statements

Thanks to AmbitiousAmoeba for the answer. The following improved code solves the problem: function filter_where( $where=”” ) { global $wpdb; $where .= ” AND (($wpdb->postmeta.meta_key = ‘original_date’ AND $wpdb->postmeta.meta_value >= ‘2000-01-01’) AND ($wpdb->postmeta.meta_key = ‘original_date’ AND $wpdb->postmeta.meta_value <= ‘2004-12-31’)) “; return where; } add_filter(‘posts_where’, ‘filter_where’); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile;

Transaction when using WP functions rather than vanilla SQL?

There is no functions in wordpress to handle transactions but you can easily use the $wpdb object to make a simple query to achieve this. The following function will start a transaction and then insert a new user into the database and finally rollback the current transaction. In order to make the transaction permanent you … Read more

SQL Query to copy value of a meta_key into another meta_key

First take a db backup! Second, in your question you mention the same meta_key, so made the following assumption: The meta_key you want to keep is “ehp_citation” The meta_key you want to change is “ehp_citation_old” * so make the correction accordingly Then you can try something like: UPDATE `wp_postmeta` AS pm_to_change LEFT JOIN `wp_postmeta` AS … Read more

How to use $wpdb to delete in a custom table

The best WP API solution for this goal is to use the delete() function to remove a row. A small example, to delete the raw ‘ID’ in the custom table ‘eLearning_progress.’ $id = 0815; $table=”eLearning_progress”; $wpdb->delete( $table, array( ‘id’ => $id ) ); But I can’t see which raw you will delete in your table … Read more

What are the common security flaws I need to look for? [closed]

Here is a modified checklist, based on my current (work-in-progress) settings/data security checklist used for reviewing Themes (the principles should be no different for Plugins than they are for Themes): Plugins should prefix all options, custom functions, custom variables, and custom constants with plugin-slug. Plugins should implement Plugin Options and Plugin Settings pages deliberately, rather … Read more

What SQL Query to do a simple find and replace

The table where your URL is saved is wp_options. You should do an update on the columns that use the URL for your site: UPDATE TABLE wp_options SET option_value = “new domain” WHERE option_name = “siteurl” UPDATE TABLE wp_options SET option_value = “new domain” WHERE option_name = “home” I might be missing some value, but … Read more

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