delete_post
fires when the post is deleted permanently, not when it is trashed. I don’t know if that is relevant but keep that in mind. That is the only real WordPress specific part of this question. The rest is bad PHP.
Variables do not expand inside single quotes. You are a sending a query to the database that literally looks like
SELECT `id` FROM $table_name WHERE `pid` = XxX
What you want is either
$wpdb->prepare('SELECT `id` FROM '.$table_name.' WHERE `pid` = %d', $post_id)
Or
$wpdb->prepare("SELECT `id` FROM {$table_name} WHERE `pid` = %d", $post_id)
To run the function when you trash the post, you probably want the one or more of the status transition hooks. But a word or caution: if you delete from your table on post “trash” you can’t reverse it. The “restore” function will fail to work correctly on these posts.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Show Similar Post Titles ( Similar to Stack Exchange )
- How do I unlock a post programmatically?
- How use %like% in sql statement wordpress
- Get page type to display content
- Use plugin or custom post type for game score functionality
- Is there a way to alter the order in which the plugins appear in the page?
- Custom plugins/Manipulated plugins: Always a terrible idea to inherit these types of WP sites that discourage updates? [closed]
- Accessing GET variable named ‘error’
- Adding Attachment Display Settings in custom media frame
- Output HTML only on individual post view
- WP_Query ordering numbers as letters
- FacetWP group listings by custom field [closed]
- Execute a plugin only on post pages
- How can i list random post from multiple category?
- How to use get_theme_mod in gutenberg editor wordpress?
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- Accessing post’s meta data based on user’s click of a post
- WordPress plugin – Error “Plugin generate 2890 characters of unexpected output when activated”
- My plugin wants to update another plugin
- View Private Published Page with URL Code (no login required)
- JS Support Ticket – Auto create WP account
- Input with spaces in Shortcode attributes overwritten by defaults
- How do I “get the next 10 posts after post_id == x”?
- Edit Yoast SEO breadcrumbs output [closed]
- switched from query_posts to WP_query, not working now?
- AJAX search posts and pages
- How would I go about creating a user ranked post popularity page?
- finding whether request is for post, and post id
- Display post lists in 2nd paragraph
- Disable woocommerce cookies and delete cart data automatically
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- custom payment gateway in woocommerce failed to connect to remote api server
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- Calling a save function from a “submit” button
- How can i summerize posts or news automatically in word press site?
- Plugin is creating posts twice
- Integrating Custom Database with WordPress
- Custom Module, Extending WP with a Plugin?
- Link Posts to External URL
- How to get Recent Post From Each Category with Thumbnail?
- help intercepting save_post through plugin
- unregister a sidebar widget
- Custom Post Type, Custom Columns List
- How to keep plugin (media-sync) running even the tab is closed?
- Is it possible to pin a post in second position from top
- Check if theme supports sidebar
- Help to Create a Simple Plugin to make a post
- How to Join wp_posts & wp_postmeta table using custom query
- How to access a wordpress plugin page or add posts without doing it from the WordPress dashboard?
- How to display the custom post related blog by category?
- WP Forms not displaying,becomming an fatal error
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Ultimate Members Default Post Layout problem
- adding dynamic/multiple slug values in ‘option_none_value’
- Rename a folder via HTML POST request
- How can I see $post object in frontend from functions.php?
- Move plugin pages from dashboard to front-end
- working code, not working – Plugin Dev
- Allow members to create groups on my site
- Cannot view Custom Post Type no matter what I try
- add tags to wordpress post using REST API
- Custom wp_list_tables redirect on specfic page
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- Paid Membership Pro displaying a user name in PHP
- Installation failed, trying to install ANY plugin
- Load my Inline js footer area
- WordPress Product Detail and catalog
- Woocommerce list variations that are added already to cart in Single Product
- Is it possible to create duplicate post on other site (either push, on publish, or pull, periodically)?
- How to use information from the database in the front-end?
- How to fix slow comment query?
- How can I get the Post ID and Post Type within a Must Use Plugin?
- Echo custom admin field into a is_single()
- How to use custom footer template in a site-plugin?
- Creating Nested custom fields
- Get content and send to 3rd party
- Confusing problem with displaying message recipient metadata
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- How to insert variable which contain array value in wp_options table?
- Custom pages with plugin
- Displaying friend’s posts only
- Update Plugin Without Overwriting Custom Settings
- Trending Tags based on post views
- Shortcode in a blog post, footer and related products stop working
- Plugin does not create a custom table upon activation
- Style WordPress Custom Post Type Single Page
- Display_rows() and column_cb() strange behaviour
- How can I pass value to function in add_menu_page?
- Multiselect value in wp_query
- Ger posts from similar tags and categories
- wp_query for more fields plugin
- Posts are deleted everyday at night
- show Visual form builder in the front end
- Issues with Post 2 Post Plugin
- WP-Snap too slow (caused by WP_Query?)
- WordPress Meta Query: Relation is not working correctly
- WordPress ultra slow if I click on posts?
- Insert data in custom table during new post creation
- Capturing POST data