Always Encounter Using ID in WordPress as a Final Solution [closed]

You’re absolutely correct that hard-coding specific IDs is a bad idea. IDs are very much subject to change, and normal activity through the UI can cause problems with any code expecting a specific ID, which makes them fragile.

However, when you see solutions involving a specific ID, you need to keep in mind that the scope of many of these solutions, especially on this site, is limited to only the specific problem that the user is asking about.

As a very simple example, a user might ask “How do I print the title of a specific page?”, and the solution proposed will be something like:

echo get_the_title( 12 );

Where 12 is the ID of a specific page.

Hard-coding the ID 12 is indeed a bad idea, however all this solution is intended to tell the user is that you can output a page title — given its ID — using the function get_the_title(). Where that ID comes from is a separate issue to the question that was asked.

So, when implementing that solution, the user is probably going to need to come up with a way to allow that ID to be dynamic. Exactly how they do that is a separate issue to the problem the solution was regarding, and will depend on context. If they needed help with that on this site, then that would require a separate question (if it hasn’t already been asked, which it almost certainly has).

The user might want to get the ID from the current post, or maybe it will be a value saved in the database through the Customiser or Settings API, or possibly passed through the URL in the query string. There’s lots of options, but the point is that how to get dynamic IDs is a separate problem to how to do something with an ID, and most solutions expect that if you need an ID to be dynamic, that you’d just combine the solution with any of those solutions for making an ID dynamic.

That’s another thing to keep in mind: The point of sites like this is to help your learn how to develop with WordPress. It’s not to just do free work and give you code to put into your site or project. Any given answer is likely focused on specific questions being asked, and won’t be a fully-formed drop-in solution. The question asker is going to need to use some development skills to properly integrate the solution into their project.