-1

I have posts that are full posts with page content and images, etc. Then I have potential future posts, which I still want to list on my category pages, but that do not have content yet and do not deserve their own page. I want to be able to set their slug to nothing, or to a standard "null" sort of value that I can query on, so that I don't add links to page stubs.

Everything I am finding on the subject is about how to remove custom post type slugs or about stubs in the Wordpress documentation.

Is there any way to make "stub" posts that don't actually have a permalink? (no post_name in the db)

Thanks for reading.

Edit

To clarify, I do not mean for these posts to be hidden from the public. I want them to show on my category pages, without a link to a single post page. Aside from not having a link, they should be just like a full, finished post. In concept, they are published posts - they are just not fleshed out yet.

However, in some places I need to be able to query all of the finished posts, or all of the stubs, separately.

Why?

I have a map showing the locations of all of the posts, finished and stub. I want them all to show on the map, but only the ones with a full write up should actually have a link to "single" page. The stubs should only show on the map, and not have links. At some time in the future, I will go back to some of the stubs and write more about them, at which time they would get a link as well.

Leaving the slug blank was a transparent way of showing that a stub doesn't have its own page, I thought. I was also concerned that marking them as Draft would have consequences when I tried to list the stubs.

I also use the post status in my workflow, so re-using the draft status for something other than actual draft status will cause confusion. I will use Review Pending instead, but perhaps you can see why I was looking for more of a solution and less of a workaround.

TL;DR?

  • 2
    As long as you don't have the post published, it won't appear in any output. You can set the post status to draft and just proceed. No reason to not have a slug in the DB. – kaiser Sep 8 '14 at 20:29
  • @kaiser that should be an answer – Tom J Nowell Sep 8 '14 at 21:18
  • Why the downvote? – Sarah Kemp Sep 8 '14 at 21:32
  • @SarahKemp Because you don't explain the why, don't show what you have tried (aside from "I searched") in code. – kaiser Sep 8 '14 at 21:42
  • @TomJNowell Not really. Would be auto flagged for length. Also there could be some explanation of what really happens, what the status is and how the loop changes for logged in/guests and administrators. I don't have the time, but if you want to write it, feel free to grab my comment as intro :) – kaiser Sep 8 '14 at 21:44
1

If you are using pretty permalinks, all posts will have slugs.

If you want to list these posts but make them unclickable, you might try creating a category especially for them, then checking for that category on your listing page.

1

As long as you don't have the post published, it won't appear in any output. You can set the post status to draft and just proceed. No reason to not have a slug in the DB. - Kaiser

Posts aren't public until they're published, and the slug has no influence on that. A blank slug gives you no benefit, and may cause compatibility issues with plugins.

You can test your theory by taking a post and making it private, then visiting its URL on another machine. The post is no longer visible, even with a slug.

Another thing to note is that by default the main loop pulls in published posts, but if you're logged in this can change ( but only for you )

  • I guess I wasn't clear, my goal is not to make the stubs private - I want them to display I just don't want them to have their own page and URL. I do want to list them along with the full posts on my category pages. I was hoping to remove the slug because that more accurately reflects my intent (which is to not provide links to non-pages) rather than mis-using part of the workflow to get the effect I am looking for. I was afraid changing the status to Draft would have other consequences, like you mention about being logged in. It seems to work though, just leaves more room for user error. – Sarah Kemp Sep 8 '14 at 23:06
  • A page that has no URL is not possible, and if they had no URL, how would you link to them? Your comment suggests you have an XY problem, aka you're trying to fix your solution, not the original problem. Perhaps you actually want to be able to embed posts inside of other posts, and a short code and custom post type would be more appropriate? Eitherway what you ask for is a very hacky way of doing it and will cause issues you haven't foreseen – Tom J Nowell Sep 8 '14 at 23:29
  • I don't want a page, I want a data point to query that I can edit in the WP backend and easily convert to a page. The only difference between what I want and a page is that slug - I didn't realize the idea was so far-fetched, considering it was relatively easily executed with the wp_unique_post_slug hook that I eventually found. – Sarah Kemp Sep 8 '14 at 23:36
  • I strongly recommend against blank slugs, looking at your questions edits, this is not the fix for your problem, it's a fix for your problems solutions problem, and could cause compatibility issues with plugins, for which there may be far easier/simpler solutions depending on what your code looks like – Tom J Nowell Sep 8 '14 at 23:38
-1
add_filter('wp_unique_post_slug', 'my_unique_slug', 1, 5);
function my_unique_slug($slug, $post_ID, $post_status, $post_type, $post_parent = 0){
    $p = get_post_field('post_content', $post_ID);
    if($p){
        return $slug;
    }
    return 'NULL';
}

This basically overrides Wordpress' default unique post slug logic and allows you to duplicate the 'NULL' value. Unfortunately it will ignore a blank or true null value and use Wordpress' automatic slug creation logic if you don't give it some value for the slug. However, it is still very easy to distinguish the stubs from the pages without messing with the workflow, and very easy to query the posts by name.

FWIW to future searchers.

Other posts in this question advise against removing the slug or overriding this. I assume that is why it has been downvoted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.