How can I avoid duplicate primary keys in SQL import?
How can I avoid duplicate primary keys in SQL import?
How can I avoid duplicate primary keys in SQL import?
This is a bit of a broad question and I don’t have time to hash out the whole thing, but your search code needs to modify the query something very much like: add_action( ‘pre_get_posts’, function ($qry) { if ($qry->is_search()) { $qry->set(‘orderby’,’title’); } } ); I have a feeling a lot of details are missing from … Read more
My solution to the problem: $prepare = array(); $in = implode(‘,’, array_fill(0, count($product_ids), ‘%d’)); foreach ($product_ids as $ids){ $prepare[] = $ids; } $prepare[] = “post”; $prepare[] = $num; $results = $this->db->get_results($this->db->prepare(“SELECT ID, post_title FROM {$this->db->posts} WHERE ID NOT IN({$in}) AND post_type=%s ORDER BY ID DESC LIMIT %d”, $prepare));
Hi The tables that you need to consider is wp_posts – Which contains all the details about the posts. wp_postmeta – Which is used to store the meta details for a post with relation to post_id. Query will be Select * FROM wp_posts a, wp_postmeta b WHERE a.post_status=”published” AND a.post_id = b.post_id AND b.meta_key = … Read more
Create a php script ( fpw-swap-thumbnails.php ) with the code below and put it in root of your site: <?php // load WordPress environment require( ‘wp-load.php’ ); $args = array( ‘posts_per_page’ => -1, ‘post_type’ => array( ‘post’, ‘page’ ), ‘post_status’ => ‘publish’ ); // get all published posts of type specified in $args $posts = … Read more
If you can answer ‘yes’ to the questions in Emetrop’s comment, then try: $sql = $wpdb->get_results(‘SELECT * from table1 WHERE id = $bransId’);
I couldn’t comment, because i dont have the rep Your code will not update because meta_key field is not in the wp_post table. First, you’ll want to query all posts where the meta_key wpcf-engine-days-to-go = 0 and then iterate through the post ID’s and make your changes to the wp_posts. Un-tested Example: $meta_value = 0; … Read more
This part require(‘./wp-blog-header.php’); is all kinds of bad idea. And if your file is indeed in plugin folder then header isn’t even in that location. Custom loads of WordPress core are brittle and the technique is typically only justifiable for performance reasons. It would be better to structure your endpoint via creating actual rewrite endpoint, … Read more
Here is one approach: $myrows = $wpdb->get_results( “SELECT first_name, surname, role, email, country, bio FROM members” ); foreach ( $myrows as $row ) { $first_name = $row->first_name; if ( ! empty( $row->bio ) ) { $first_name=”<a href=”#”>” . $first_name . ‘</a><div class=”bio” style=”display: none;”>’ . $row->bio . ‘</div>’; } echo “<tr><td>” . $first_name . “</td><td>” … Read more
As David pointed out, wpdb::query() does not allow multiple calls. So yes, it is because of having the “SET @newnum = 0;” before your actual query. This kind of query is simply not possible as the backend prevents that in order to protect against SQL injection attacks. Besides of that, the technique I described in … Read more