Support » Fixing WordPress » Register a custom post type as public = false but appear in search results

  • Is this possible? I dont want the pages to exist ie. they go to 404 if you attempt to access them but I want them to be included in the search.
    ‘public’ => false

    This would be cool but I can use redirects if I have to but I prefer not to.

Viewing 9 replies - 1 through 9 (of 9 total)
  • i need to know this too,


    Sorry i don’t understand this… my english is poor… Can you explain me with an example, so i can help you?

    With “search” do you mean the internal search of WP?

    hi YouON, thanks for the reply,

    no, through a search engine,

    for example –
    Im building a ‘one page layout’, all content (‘about’, ‘content’, ‘people’ etc) exists on the front page template. like this website;

    I dont want to use Pages or Post to organise the content (e.g ‘about’, ‘content’, ‘people’),
    so i’ve created a custom-post-type called ‘Sections’. I want the content in each ‘Section’ post-type to be seen by search engines (on my ‘one page layout’), but i dont want a the url to be seen by the search engines.

    the reason i decided to use a custom-post-type over ‘pages’ or ‘post’ is the ability to hide the URL using ‘public = false’, but i dont want to hide the content from SE’s aswell…

    ah ok… but if you don’t link a page probably the search engine will never index it. BTW you can block it via robots.txt 😉

    I was actually referring to the internal search
    What I wanted to do was create a custom post type in the normal way but exclude it from the internal search. If I changed the setting so it didn’t appear in the internal search then linking to the post gave me a 404.
    Is this possible and if so how? Please advise – thanks

    'public' => true
    'exclude_from_search' => true

    This way custom posts should be accessible, but won’t be included in search.

    “Search” refers to WordPress internal search only. If you want to hide a specific post type from search engines (e.g. Google), you have to add a condition to your header.php, like this:

    <?php if ( get_post_type() == 'custompost' ) { ?>
    <meta name="robots" content="noindex,follow" />
    <?php } ?>

    I hope I understand your question correctly because in the first post you ask how to make pages inaccessible but visible in search, and in the last post it’s the other way round 🙂

    chadrew you are correct I’ve gotten confused about what I was trying to achieve, I’ve revisited the project and what I did. I had a workaround but I wanted a clean way to do the following:
    Hide the posts ie. permalinks don’t exist they go to 404 but the posts still appear in the search.

    The reasons for this is that this particular custom post type posts appear as a listing on an overview page therefore any search result for that post type the link goes to the overview page (I customise the results page to achieve this) and not the post permalink.

    Basically I wanted to achieve this without having to put a redirect on the single-mycustomposttype.php page that redirects to the overview page.

    Very interesting, I guess you could use 'public' => false and 'exclude_from_search' => false, but I’m not sure if one prevents the other from working.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Register a custom post type as public = false but appear in search results’ is closed to new replies.