New answers tagged

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)" );


0

I assume you're already properly using the WP Metadata API https://codex.wordpress.org/Metadata_API to attach the field to new comments and you just want to backfill for existing comments by stuffing the database? If it was my problem, I wouldn't bother and would assume in my code that absence of meta implied no likes. If you use update_meta_data() to ...


0

The code is fine, I can't see any need to modify the query - I think you're missing the third argument in your get_post_meta call: $postACF_sc = get_post_meta($postId, 'sc_link', true /* $single */); You might also want to add this snippet just before the foreach to save multiple database queries: update_postmeta_cache( wp_list_pluck( $posts, 'posts_id' ...


0

To get the custom fields for a post you would need to add something like the following: d.meta_value (in the select clause) LEFT JOIN '.$var_setting['table_postmeta'].' d ON d.post_id = b.ID (in the from clause) I don't know the plugin so I can't promise it will work but this is how you join to the postmeta table to pull the custom fields. Hope ...


0

ok, I was close and I have solution: SELECT wp_posts.ID, wp_postmeta.meta_value FROM wp_postmeta INNER JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id) WHERE 1=1 AND wp_postmeta.meta_key = ...


0

SELECT * FROM wp_postmeta WHERE NOT EXISTS (SELECT * FROM wp_posts p WHERE wp_postmeta.post_id = p.ID)this will find all the broken metadata: SELECT * FROM wp_postmeta WHERE NOT EXISTS (SELECT * FROM wp_posts p WHERE wp_postmeta.post_id = p.ID) But you can probably find a plug-in to cleanup your database ;-)


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 " . ...


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( ...


-1

The field name is a reserved name. Changing from key to id has solved the issue.


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 ...


0

Why did it happen? It's hard to tell for sure because there are lots of variables to consider: mistakes made in exporting or importing, MySQL version etc. This is rather specific MySQL database question and doesn't have much to do with WordPress itself. To get a specific non-speculative answer to question why, I suggest to ask it in SO or DBA with plenty ...


0

I haven't tested this, but this should give you the count of skus for each post_id: SELECT post_id, COUNT(`post_id`) AS sku_count FROM `wp_postmeta` WHERE `meta_key` LIKE '%sku%' GROUP BY `post_id` To have it return only rows where the count is greater than one is trickier. Off the top of my head I'd probably use the above as a subquery: SELECT * from ...


0

you can export tables of your database that you want to transfer, and Import to another database, then you should change Prefixes of those .


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


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 ...


0

if($search->keyword){ $project_args['s'] = $search->keyword; } That was the culprit. FML! Everything else was correct.


0

For this I use WP-CLI because I find it the easiest and it takes care of serialized data. wp search-replace 'http://example.dev' 'http://example.com' --skip-columns=guid There is also an option that writes your changes into an SQL file instead of manipulating the actual database: wp search-replace foo bar --export=database.sql



Top 50 recent answers are included