Domanda

Is it possible to create a search page that will search for a keyword only in a custom post type that has the status "draft?"

Basically, I have a lot of data I was planning on importing as a custom post type. The data would be simple, "name", "answer", "notes." However, I don't want this data published because each custom post would have almost no data and the site would then have 5,000 spammy pages.

However, users frequently want to know the "answer" for certain "names," and I need to give them the ability to search and find.

È stato utile?

Soluzione

It's possible to search within drafts by setting the post_status argument to draft in your search query, however, a better option is to control things with the arguments passed to register_post_type.

We first set public to false, which will hide the post type everywhere- front and back end. We then selectively enable show_ui to get the admin UI, and set exclude_from_search to false so they show up in front end searches. We also set rewrite to false, so WordPress doesn't generate rewrite rules for this post type.

You will then have published posts that are searchable, but they will have no individual pages on the front end.

$args = array(
    'public' => false,
    'show_ui' => true,
    'exclude_from_search' => false,
    'rewrite' => false,
    'label' => 'Name',
    // your other arguments...
);
register_post_type( 'name', $args );
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top