I see people using this to pull in page content on their home pages, remove specific categories from archives etc.. e.g.
$post = get_post( 5 );
Someone suggested this was bad practice. Why is it bad and what should users do instead?
For starters let's dive into what is
Issues with using IDs
So first there are some conceptual problems with it. It's not content. It's not something user creates, manipulates, or (most of the time) aware of. WP is (by design) pretty sneaky about exposing IDs to the users and almost never does it, spawning quite a few plugins around just for that purpose.
As a product of it not being content (or value meaningful for human) it's not self–documenting. There is no way whatsoever to infer what post
And finally, while ID uniquely identifies post in specific database, it's much less certain to do so as soon as content starts moving around between databases and/or even different systems.
So what are better options?
I've observed two typical reasons to retrieve and make use of standalone post.
Working with specific content in site
The persistent content is typically pretty static and in most cases can be identified by title. For example in your snippet low ID as
For retrieval of such content
So using better identification (and producing self-documenting code while at it) your snippet turns into:
Working with specific place in site
Another case is when the post is used as a place in site, rather than specific content. For example we would like to retrieve site's FAQ, but not sure (or care) what it's precisely named and other content details.
But if we know where is it in site's structure we can use
In more complicated cases there aren't always well–fitting functions. Sometimes it boils down to using
This question is going to get some opinion based answers, but well, I'll give it a try.
There are a couple of reasons why someone might've told you that, it would be great to know the context also.
I built something similar to that a couple of weeks ago, I wrote a plugin for it. And in the theme I just called the plugin's function. The option to change the ID was in a metabox in each post, the user just had to check a checkbox in order to select the ID of the post he wanted to display in the main site.
As you can see, most of the reason are related with whom is going to have to change the value. And creating a proper "options panel" is also useful because you can set proper data validation, in case someone makes a mistake.
If you give me more context I might be able to expand my answer, I hope you find it useful.