How to combine multiple wp_insert_post into one in order to gain better performance

I would advise using wp_insert_post() and putting you text files into a CSV CSV Post Title,Post Content, “title”, “content”, “title”, “content”… PHP $path = “/posts.csv”; //require __DIR__ . “$path”; $file = fopen(__DIR__ . $path, ‘r’); while (($line = fgetcsv($file)) !== FALSE) { //$line is an array of the csv elements $post[“id”] = wp_insert_post( array( “post_title” … Read more

Duplicated site isn’t recognized as a site

Error is from the last command wp search-replace “${domain}” “test” –allow-root. Your WordPress site is not yet installed and you want to execute command which require WordPress to be installed. Earlier in script you are dropping test database and creating new one, but you have to fill it with WordPress tables. Without this tables WordPress … Read more

$wpdb is not initiating

You have written $wpdb incorrectly (3x) in your code example. If it is an exact copy it will never work. And you have a space in your SQL after prefix.’ which shouldn’t be there. And ‘From’ shoul dbe all caps. Try this: global $wpdb; $sql=”SELECT * FROM ” . $wpdb->prefix . ‘my_first_plugin’; $result = $wpdb->get_results($sql);

Is it necessary to do validation again when retrieving data from database?

The short answer is “yes”, the longer answer is “it depends”. Why do you need to validate? because if you have code, which if used with wrong parameters will delete wordpress (very bad example I know), you should made double sure that it is not triggered by some DB corruption, or more likely, misbehaving filter. … Read more

How to access custom WordPress database tables

Are you sure that’s the table name? Usually on install WordPress prompts you to setup a table prefix so the default isn’t wp_. Additionally, you need to call the global $wpdb object so it’s accessible to use: global $wpdb; $user_count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->users” ); echo “<p>User count is {$user_count}</p>”; Finally, to prevent … Read more

Show data from one Custom Post Type in another Custom Post Type

Add a field to your form that allows selection of a machine. You can use get_posts to generate a select element: $args = [ ‘posts_per_page’ => -1, ‘post_type’ => ‘machine’ ]; $machines = get_posts( $args ); if( ! empty( $machines ) ){ echo ‘<select name=”_machine_id”>’; foreach( $machines as $machine ){ echo ‘<option value=”‘ . $machine->ID … Read more

What does wp_term_taxonomy.parent reference?

WordPress doesn’t use actual FOREIGN KEY constraints in MySQL. So, technically, wp_term_taxonomy.parent is merely an integer. However, what you’ve found is correct: it refers to a term in wp_terms by its term_id. But, as you’ve also noticed, the term_id and term_taxonomy_id should always be the same. The reason they both exists is historical. Prior to … Read more

Code is providing a row of data but not formatting it as table

It’s not displayed as table, because you don’t return correct HTML code. Let’s take a look at your code (I’ve put comments at end of incorrect lines): $content=”<table>”; $content .= ‘</tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previous Week Totals</th></tr>’; // <- here you open TR with </tr>, so it’s already incorrect $results = $seconddb->get_results( ‘ SELECT * FROM seconddb_PontoonBoats_LineOne_2Log’ … Read more

Is it necessary to auto delete my WP plugin database tables when users deactivate/delete my plugin?

In my opinion, a best practice would be to clean everything on uninstallation. It’s also mentioned as a best practice in the docs: When your plugin is uninstalled, you’ll want to clear out any plugin options and/or settings specific to to the plugin, and/or other database entities such as tables. However, if you’re struggling to … Read more