How to Delete Posts by title?

Like keepkalm said I’d find the list of post IDs from the database: select id, post_title FROM wp_posts where post_title like ‘%Pharmaton%’ or post_title like ‘%Winston Blu%’ or post_title like ‘%Kefir%’ or post_title like ‘%Tetradox%’ or post_title like ‘%Passport Sco%’; and then use the list of IDs with wp-cli’s wp post delete which accepts a … Read more

How to pass username into form that sends data to database

If you want to output the $id, you need to echo. Also be sure to use esc_attr() as a good security practice. <input type=”hidden” name=”id” value=”[insert_php]echo esc_attr( $id );[/insert_php]”> In addition, as was noted in another answer, you’re calling it an ‘id’, but you’re actually using the login (username). If all you need is the … Read more

Efficiently loop over huge number of posts

Call a external script: Your function look like this: <?php function modify_posts() { $number_posts = 10; $offset = 0; $success=”success”; while ( ‘success’ === $success ) { $url = add_query_arg( array( ‘num’ => $number_posts, ‘off’ => $offset, ‘abs’ => urlencode( ABSPATH ) ), plugins_url( ‘remote_get.php’, __FILE__ ) ); $response = wp_remote_get( $url ); if ( … Read more

Complicated MySQL Query

Why not just use WP_Query for this instead of inventing the wheel all over again? I’m pretty sure you can solve this with a meta query within your WP_Query. See the codex.

MySQL: get post_tag items that are tags (not SEO keywords)

Fetching all tags of post: SELECT p.id, p.post_name, c.name, GROUP_CONCAT(t.`name`) as tag FROM wp_posts p JOIN wp_term_relationships cr on (p.`id`=cr.`object_id`) JOIN wp_term_taxonomy ct on (ct.`term_taxonomy_id`=cr.`term_taxonomy_id` and ct.`taxonomy`=’category’) JOIN wp_terms c on (ct.`term_id`=c.`term_id`) JOIN wp_term_relationships tr on (p.`id`=tr.`object_id`) JOIN wp_term_taxonomy tt on (tt.`term_taxonomy_id`=tr.`term_taxonomy_id` and tt.`taxonomy`=’post_tag’) JOIN wp_terms t on (tt.`term_id`=t.`term_id`) GROUP BY p.id order by p.id … Read more

How to create a post based on data in a table?

yes that’s possible, you can create your custom post type and use MySQL query to fetch from csv file, and use insert into post function within the loop. you can use LOAD DATA INFILE query to fetch from excel and then use wp insert post function to insert into db. the query will look like:- … Read more

Using wp config to connect to a DB from a plugin

I’m guessing this is a custom “plugin” where you are wanting to run a file externally that connects to the WordPress database, not really as a standard plugin which loads within WordPress environment, as in that case as @belinus says you can just use $wpdb class. Anyway, since ABSPATH is defined IN wp-config.php, you can’t … Read more