Flushing the rewrite rules – which you can do just by visiting the Settings -> Permalinks page – was a good step to take, because it’s usually the overlooked cause of these sorts of issues.
However as Milo said in the comments, in this case, it’s just that the publicly_queryable
argument needs to be true if you want these posts to display on the frontend.
From the docs for register_post_type():
public
(boolean) (optional) Controls how the type is visible to authors (show_in_nav_menus
,show_ui
) and readers (exclude_from_search
,publicly_queryable
).
Default: falsepublicly_queryable
(boolean) (optional) Whether queries can be performed on the front end as part of parse_request().
Default: value of public argument
As you can see – and again as Milo said – just avoiding setting publicly_queryable
will make things a bit simpler for you in this case.
I would definitely recommend reading up on those docs to understand what each of the attributes do, but I realise it can be difficult to get your head around at first!
As for your second question in the comments:
Does
public
affect if the template is shown? Andhas_archive
orrewrite
?
-
public
is a quick override to generally control all of the backend and frontend visibility of your post type in one go: unless you override it with any of the four more explicit options as seen above. For the frontend, these arepublicly_queryable
, as we have already addressed, andexclude_from_search
. You’ve already setexclude_from_search
to true, so no matter what you set forpublic
, this post type won’t be found in searches (OR taxonomy term lists). -
has_archive
won’t affect whether your single post types can be viewed, but it will turn on and off the option to view the archive ‘loop’ of all of your posts – at http://example.com/your_rewrite_slug -
rewrite
doesn’t affect public visibility of your posts; just what the URL will be. The URL has to be something though, so if you don’t set the rewrite value, it’ll just default to your post_type name – in this case ‘producto’
Each of these are also covered in the docs, so I’ll mention again – definitely read up on it. The investment will be worth it! 🙂