Hot answers tagged

6

For the permanent solution, your SQL query is slightly off - you need: UPDATE db1357924680.wp_posts SET post_content = REPLACE( post_content, '[print_me]', '' ) WHERE post_content LIKE '%[print_me]%' MySQL replace example


4

There is an easier way to do this: add_filter( 'the_content', 'my_post_content_remove_shortcodes', 0 ); function my_post_content_remove_shortcodes( $content ) { /* Create an array of all the shortcode tags. */ $shortcode_tags = array( 'shortcode_1', 'shortcode_2', 'shortcode_3' ); /* Loop through the shortcodes and ...


2

You should use $wpdb->prepare for queries, as it does all the sanitizing and escaping for you. Also, key is reserved as a field name in MySQL: function ch_details_from_id($id) { global $wpdb; // or try using " . $wpdb->prefix . "ch_guests $query = "SELECT * FROM $wpdb->ch_guests WHERE guest = %d"; $details = $wpdb->get_results( ...


2

The direct answer to the question "Is there a way to get 3+ dimensional array from a single MySql command" would be yes, sort of - WordPress routinely stores and retrieves multidimensional data from MySQL rows by serialize()ing and unserialize()ing structured data to/from a string format, so it's certainly possible using WordPress's database interaction ...


2

No, wpdb::delete does not handle anything other than WHERE field = X. You can just use the query method instead: $ids = implode( ',', array_map( 'absint', $ids ) ); $wpdb->query( "DELETE FROM table_name WHERE ID IN($ids)" );


1

Here issue with the column name. You are using column key in the query which is the default keyword/index in mysql. For resolving this kind of issue just use the "Grave accent(`)' symbol in the query for the column name, No need to change the column name. So in your case the right query is $details = $wpdb->get_results("SELECT * FROM " . ...


1

Because $pageposts is an array of post IDs, but you need to pass a post object to setup_postdata - pull the objects instead: SELECT $wpdb->posts.* [rest of query] Note that, since you're not paginating, you don't need SQL_CALC_FOUND_ROWS



Only top voted, non community-wiki answers of a minimum length are eligible