What’s wrong with my $wpdb query?

When you use $wpdb->prepare the placeholder %s is replaced with something between quotes, so, your query becomes: “SELECT * FROM ‘wp_users’ WHERE ID = 1” but table names in SQL queries must not be wrapped in quotes. So, the right way is: $sql = $wpdb->prepare( “SELECT * FROM {$wpdb->users} WHERE ID = %d”, 1 ); … Read more

Link to handle $_GET request

If this is in the admin, use the action parameter: <a href=”https://wordpress.stackexchange.com/questions/159391/<?php echo esc_url( admin_url(“?action=delete_ticket&ticket_id=$ticket->ID” ) ?>”>Delete item</a> …and then hook appropriately: function wpse_159391_delete_ticket() { if ( isset( $_GET[‘ticket_id’] ) ) { // delete it! } } add_action( ‘admin_action_delete_ticket’, ‘wpse_159391_delete_ticket’ ); For the front-end, you can just append your parameters to the current url and … Read more

How to Determine a Post’s Last Edited Date?

If I got your question right, and you want posts created/modified between 3 years ago and today, try this query: SELECT p.ID, concat(‘http://www.toronto.com/restaurants/’, p.post_name) FROM wp_posts p WHERE p.post_type=”restaurant” AND p.post_status=”publish” AND p.post_modified > DATE_SUB(now(), INTERVAL 36 MONTH); Because your DATE_SUB returns something like this: NOW – 3 years, so, it’s something along the lines … Read more