Stuff made easily on Wordpress.
composer require daidais/morepress
Create from id:
$mp_post = new \Morepress\Post(23);
Create from \WP_Post:
global $post;
$mp_post = new \Morepress\Post($post);
Check if exists:
if($mp_post->exists())
{
// Do stuff
}
Get attribute:
$mp_post->ID;
$mp_post->post_name;
// etc.
Update post:
$mp_post->update(array(
'post_status' => 'publish',
));
Add meta:
$mp_post->addMeta('meta_key', 'meta_value', true);
Update meta:
$mp_post->updateMeta('meta_key', 'meta_value', 'prev_meta_value')
Get meta:
$mp_post->getMeta('meta_key', true);
Delete meta:
$mp_post->deleteMeta('meta_key', 'meta_value');
Get time:
$mp_post->getTime();