corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delete Post Meta

noplanman opened this issue · comments

  • Corcel Version: 5.0
  • Laravel 8.55.0
  • PHP Version: 8.0.9
  • Database Driver & Version: MariaDB 10.6

What is the proper way to delete post meta?

I'm talking about removing the meta item completely, not just setting it null with ->saveMeta!

Hi @noplanman, I created a PR that help you with this functionality

@kayobruno Nice, hope it gets merged! 🤞

To properly delete a post meta item using Corcel, you can use the deleteMeta() method. Here's an example:

$post = Post::find($postId);
$post->deleteMeta('meta_key');

In the above code, replace $postId with the actual ID of the post you want to delete the meta from. The 'meta_key' parameter should be replaced with the key of the meta item you want to delete.

The deleteMeta() method will remove the specified meta item completely from the post. It does not just set it to null like saveMeta() does.

Make sure you have the necessary permissions and authentication to delete the meta item.