Deleting data from a custom table in WordPress

I am trying to delete records from my custom table but it does not delete anything. Here is my code: <?php global $wpdb; $retrieve_data = $wpdb->get_results( “SELECT * FROM wp_paypal” ); // some code to display here… ?> <form method=”post” enctype=”multipart/form-data”> <td><input type=”submit” name=”delete” value=”Delete” /></td> </form> <?php $myid= $retrieved_data->id; if (isset($_POST[‘delete’])) { //global $wpdb; … Read more

posts_per_page doesnt work

Here is the my custom query ; <?php $Poz = new WP_Query(array( ‘posts_per_page’ => 3, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘no_found_rows’ => true, ‘update_post_term_cache’ => false, ‘update_post_meta_cache’ => false, )); // The Query $the_query = new WP_Query( $Poz ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/70424/<?php the_permalink(); ?>” title=”<?php … Read more

How To Get Some Data From WordPress Database Using WordPress $wpdb Query?

I am trying to get some data from WordPress database tables in a plugin. For that, I am using the below code… global $wpdb; $findID = $wpdb->get_var(“SELECT ID FROM wp_posts WHERE post_name=”hello-world””); echo $findID; But it not giving me the post ID in echo? Is there anything wrong…??? 2 Answers 2 Just to clarify the … Read more

Check if post exists

How can I check if post with name for example Weather exists? If not I want to create it. function such_post_exists($title) { global $wpdb; $p_title = wp_unslash( sanitize_post_field( ‘post_title’, $title, 0, ‘db’ ) ); if ( !empty ( $title ) ) { return (int) $wpdb->query(“SELECT FROM $wpdb->posts WHERE post_title = $p_title”); } return 0; } … Read more

Is it good practice to use wpdb->query() function?

I am using custom php code to perform data insertion, deletion, updating and other tasks. I am able to insert data into a table in two different ways, $wpdb->insert($table_name, array(‘id’ => NULL, ‘name’ => ‘$name’, ’email’ => ‘$email’, ‘city’ => ‘$city’)); and $sql = “INSERT INTO $table_name VALUES(”, ‘$name’, ‘$email’, ‘$city’)”; $wpdb->query($sql); Is it a … Read more