• Resolved someonebutwhere

    (@someonebutwhere)


    Hi there,

    Do you have a snippet that would turn on the checkbox for all post-types? Almost all new content on one of my sites is hidden.

    I’ve seen the snippet which makes exclude by default for certain post-types but my php is not good enough to rewrite the code for a global setting =)

    Thanks for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor pronskiy

    (@pronskiy)

    Hi @someonebutwhere,

    Need some clarification 🙂
    So you want all newly created items of any post-type to be excluded by default? Did I get you right?

    Regards,
    Roman

    Thread Starter someonebutwhere

    (@someonebutwhere)

    Hi Roman, sorry about my delay in replying…

    You have me exactly right – all new, all post-types =)

    Cheers!

    Thread Starter someonebutwhere

    (@someonebutwhere)

    Hi! The reason for wanting to be able to exclude by default is that most of the posts I make for this one site should be non-searchable, whereas other posts are available to the public and these should be searchable. It would be easier to enable searching on the few, rather than disabling on the many, and would also assist by not showing a sensitive post if I missed checking the box. If you have a snippet that could create this function I’d really appreciate it!

    Kind regards

    Plugin Contributor pronskiy

    (@pronskiy)

    Hi @someonebutwhere!

    You can add the following code to you functions.php:

    
    add_filter('default_content', 'excludeNewPostByDefault', 10, 2);
    function excludeNewPostByDefault($content, $post)
    {
        if ('post' === $post->post_type) {
            do_action('searchexclude_hide_from_search', array($post->ID), true);
        }
    }
    

    This will make hide check-box checked by default for newly created posts. I.e. posts will be hidden by default unless you explicitely uncheck the check-box.

    As for existing posts, I would recommend using bulk action to hide them.

    Please let me know if this works for you.

    Cheers!
    Roman

    Thread Starter someonebutwhere

    (@someonebutwhere)

    Thanks so much – that works perfectly on new posts! To exclude ALL new post types I’ll need an array. Sorry, when I used the term Posts above I meant it in the generic sense… =)

    Thanks in advance!
    Kind regards

    Thread Starter someonebutwhere

    (@someonebutwhere)

    I finally put some time into working this out.

    This excludes both posts and pages by default. I needed this because I have a page based site and more often need them hidden from search.

    add_filter('default_content', 'excludeNewPostByDefault', 10, 2);
    function excludeNewPostByDefault($content, $post)
    {
        if ('post' === $post->post_type || 'page' === $post->post_type) {
            do_action('searchexclude_hide_from_search', array($post->ID), true);
        }
    }

    If you want to have everything hidden by default then take out the if statement:

    add_filter('default_content', 'excludeNewPostByDefault', 10, 2);
    function excludeNewPostByDefault($content, $post)
    {
            do_action('searchexclude_hide_from_search', array($post->ID), true);
    }

    Hope this helps someone else.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Enable Exclude by default – all items’ is closed to new replies.