WordPress.org

Ready to get started?Download WordPress

Forums

Register a custom post type as public = false but appear in search results (10 posts)

  1. c.note
    Member
    Posted 2 years ago #

    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.

  2. ococa252
    Member
    Posted 2 years ago #

    i need to know this too,

    anyone?

  3. YouON
    Member
    Posted 2 years ago #

    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?

  4. ococa252
    Member
    Posted 2 years ago #

    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;
    http://www.bingu.name/demo/wpmiworks/

    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.

  5. ococa252
    Member
    Posted 2 years ago #

    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...

  6. YouON
    Member
    Posted 2 years ago #

    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 ;)

  7. c.note
    Member
    Posted 2 years ago #

    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

  8. chadrew
    Member
    Posted 2 years ago #

    '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 :)

  9. c.note
    Member
    Posted 2 years ago #

    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.

  10. chadrew
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.