最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Forcing two or more custom post type to be private

programmeradmin2浏览0评论

I registered a new custom post type and forced it to be private, but now I need to use three custom post type. I registered the second one, but I don't know hot to set the code to force the second one.

Here is the code I used to force the first CPT ('my_post_type1')

function force_type_private($post)
{
    if ($post['post_type'] == 'my_post_type1') {
        $post['post_status'] = 'private';
    }
    return $post;
}
add_filter('wp_insert_post_data', 'force_type_private');

How can I force the second ('my_post_type2')?

Thank you very much

I registered a new custom post type and forced it to be private, but now I need to use three custom post type. I registered the second one, but I don't know hot to set the code to force the second one.

Here is the code I used to force the first CPT ('my_post_type1')

function force_type_private($post)
{
    if ($post['post_type'] == 'my_post_type1') {
        $post['post_status'] = 'private';
    }
    return $post;
}
add_filter('wp_insert_post_data', 'force_type_private');

How can I force the second ('my_post_type2')?

Thank you very much

Share Improve this question edited Mar 19, 2020 at 23:08 Tom J Nowell 61.1k7 gold badges79 silver badges148 bronze badges asked Mar 19, 2020 at 22:20 Oh-SusiOh-Susi 1
Add a comment  | 

1 Answer 1

Reset to default 0

You can add multiple compared condition variable in single if condition using logical OR operator.

For more knowledge of Logical condition click

function force_type_private($post)
    {
        if ($post['post_type'] == 'my_post_type1' || $post['post_type'] == 'my_post_type2') {
            $post['post_status'] = 'private';
        }
        return $post;
    }
    add_filter('wp_insert_post_data', 'force_type_private ');
发布评论

评论列表(0)

  1. 暂无评论