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
- How to structure a plugin
- is_plugin_active function doesn’t exist
- Custom pages with plugin
- How can I make it so the Add New Post page has Visibility set to Private by default?
- WordPress Plugin Development In MVC Architecture, How?
- Checking if an attribute exists in a shortcode
- How to add option box in “Edit Post” plugin API?
- Delete Post With No Traffic?
- Create page when plugin is activated
- Automatically Creating Posts for Popular Forum Topics or Products [closed]
- How can I limit functionality in one version of a plugin?
- How to show custom message once on plugin activation?
- How to list the Hooks and order of execution in current loading page? [duplicate]
- How to load a new template page according to a particular URL?
- WordPress network: set themes and plugins for new blog
- Updating post meta for custom post types
- How to extract images of post and pages excluding header and logo image in wordpress?
- Failed to invoke other hook from the init hook
- Is there a plugin to display certain posts on certain pages? [closed]
- Can a plugin add to header/footer/body content?
- REST-API: extend media-endpoint
- Is there a way to alter the order in which the plugins appear in the page?
- 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 to use get_theme_mod in gutenberg editor wordpress?
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- WordPress plugin – Error “Plugin generate 2890 characters of unexpected output when activated”
- My plugin wants to update another plugin
- How do I “get the next 10 posts after post_id == x”?
- Edit Yoast SEO breadcrumbs output [closed]
- How would I go about creating a user ranked post popularity page?
- Disable woocommerce cookies and delete cart data automatically
- Customization API for plugin development
- Fromcraft Plugin On click submit button [closed]
- How to redirect users to their profile after they successfully edit their profile
- Add category selection to custom post type (plugin)
- Custom post types – remove default post supports through empty array?
- How to get all posts belongs to a user between a certain date
- Loop in elementor custom widget not working
- Moving FB comments at the end of page
- Minimize and Uglify WordPress Plugin Files
- How can i summerize posts or news automatically in word press site?
- Plugin is creating posts twice
- unregister a sidebar widget
- How to keep plugin (media-sync) running even the tab is closed?
- Is it possible to pin a post in second position from top
- 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?
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- 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
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- 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
- How to use information from the database in the front-end?
- How can I get the Post ID and Post Type within a Must Use Plugin?
- 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?
- Update Plugin Without Overwriting Custom Settings
- Plugin does not create a custom table upon activation
- How can I pass value to function in add_menu_page?
- Ger posts from similar tags and categories
- wp_query for more fields plugin
- 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
- Checking url from plugin [duplicate]
- Custom feed parameters / Template overriding
- Plugin to display text before a post
- How to add image for custom taxonomy
- Does anyone have the Custom Post Permalinks plugin from John P. Bloch? [closed]
- Why haven’t I see plugins using get_file_data to handle retrieving plugin version?
- How can I properly sanitize the update_option in WordPress?
- Create Custom Coupon Type
- Take Elementor For Email FIeld Check if user is registered. IF not registered then register on woocommerece
- warning wp session
- Accessing Correct Database to Create REST API Endpoint