Preview doesn’t work on published posts, shows no results found 404
-
Hi
In a custom post type, when I create a post and preview it before publishing, the preview works fine. But once published, if I make changes and click the preview changes, it shows on that page:
No Results Found
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.Any ideas?
Thanks
-
Honestly not sure what’s going on there, as that’s behavior I can’t recall ever having encountered before. I’m hard pressed to say it has anything to do with our plugin specifically, since we only handle the registration of the post type. We don’t interject ourselves in any way regarding post publishing.
For whatever reason, it seems like it’s not managing to find a post to use in the preview. Out of curiosity, have you done any sort of query filtering via pre_get_posts? Perhaps you have a plugin that is doing something like that without you specifically knowing.
If this is a dev site, then see if you still get the same behavior with all other plugins disabled, and one of the twenty* themes active. If the issue goes away, slowly start reactivating the plugins until the behavior comes back. Once it does, then we know the culprit that is causing some sort of conflict and could go from there.
I am using a customized single.php file for these but I didn’t tinker with the loop.
I am using the FacetWP plugin to do custom filter on the post index page but nothing on a single post page, perhaps it still messes with it. I will test on staging and see if that is related. Thanks
Yeah, the FacetWP part sounds like it’d be a lot more involved. The customized single.php isn’t going to have any effect as that’s loaded/run after the query has been made already.
Let me know if you come up with anything, as I am curious what’s going on.
Hi,
Check the permalinks for the posts that don’t show up. I’m having a similar problem, and I’ve found that, if there is a space in the post title, it’s replaced by a dash in the permalink. But somewhere in the CPT UI plug-in, that URL is converted to use underscores instead of dashes for spaces.
A work-around is to edit the permalink for your post and replace the dashes with underscores. There’s got to be a better solution, though. There must be some way to tell WordPress to use underscores instead of dashes, or to tell CPT UI to use dashes in the permalink URLs.
I found the following help topic: https://docs.pluginize.com/article/135-dashes-in-post-type-taxonomy-slugs-for-url-seo. This says something about changing the Custom Rewrite Slug to tell CPT UI to use dashes in URLs. But it isn’t enough information for a newbie like me. It just says to fill in the field. It doesn’t give a clue about what to actually put in the field.
Any advice would be appreciated!
We only do conversion of dashes to underscores for the post type/taxonomy slug field, when the user is registering a new type/tax within our plugin. We don’t do anything like that with the post permalinks/titles for newly written posts being created within the post type.
If the OP in this thread had a space in the post type slug and it was causing 404 issues with the previews, then that was a detail that was not originally brought up.
Regarding your last part about what to put in the “Custom rewrite slug” field, if you wanted a a post type for “Team Profiles”, the slug field would be something like “team_profiles”, and the rewrite slug would be “team-profiles”. This way, when visiting one of the profiles on the frontend, the url would have “team-profiles” in it. For setting up queries via WP_Query or other WordPress functions that take a post type parameter, you’d pass in “team_profiles”.
My original post was accurate, I’m sure i understand the space in title issue. I get a 404 with preview only after I publish the post and the post itself looks fine. Meaning no 404 for live post, but 404 for preview of further updates to post.
I have turned off facetwp and issue remains.
I should mention I tested this on regular post and issue does not happen, this is only on the custom post.
Any other pointers of how to diagnose further?
Just to re-iterate, the space vs dashes vs underscores that CPTUI affecs with has nothing to do with creating posts for the post type. That’s just for when creating a new post type/taxonomy in our plugin screens.
Regarding the preview part, I don’t really have anything new compared to my previous replies. Best I can offer is perhaps try registering a post type outside of CPTUI and see if it happens for that one as well. If it does, then the issue is coming from somewhere else. If it doesn’t then I’m curious what your post type settings are within CPTUI to cause it.
Those can be exported via the tools menu, and copy/pasted for me, if you want right away.
Btw I create a new CPT and it works fine for previews.
Not sure which part you wanted so here is export and the code as well:
{"resource":{"name":"resource","label":"Resources","singular_label":"Resource","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"","supports":["title","editor","thumbnail","excerpt","custom-fields","revisions","author","post-formats"],"taxonomies":["post_tag","resource_type"],"labels":{"menu_name":"Resources","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""},"testable":{"name":"testable","label":"Testables","singular_label":"Testable","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"","supports":["title","editor","thumbnail"],"taxonomies":[],"labels":{"menu_name":"","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""}}
the get code:
function cptui_register_my_cpts() { /** * Post Type: Resources. */ $labels = array( "name" => __( 'Resources', '' ), "singular_name" => __( 'Resource', '' ), "menu_name" => __( 'Resources', '' ), ); $args = array( "label" => __( 'Resources', '' ), "labels" => $labels, "description" => "", "public" => true, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => false, "rest_base" => "", "has_archive" => false, "show_in_menu" => true, "exclude_from_search" => false, "capability_type" => "post", "map_meta_cap" => true, "hierarchical" => false, "rewrite" => array( "slug" => "resource", "with_front" => true ), "query_var" => true, "supports" => array( "title", "editor", "thumbnail", "excerpt", "custom-fields", "revisions", "author", "post-formats" ), "taxonomies" => array( "post_tag", "resource_type" ), ); register_post_type( "resource", $args ); /** * Post Type: Testables. */ $labels = array( "name" => __( 'Testables', '' ), "singular_name" => __( 'Testable', '' ), ); $args = array( "label" => __( 'Testables', '' ), "labels" => $labels, "description" => "", "public" => true, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => false, "rest_base" => "", "has_archive" => false, "show_in_menu" => true, "exclude_from_search" => false, "capability_type" => "post", "map_meta_cap" => true, "hierarchical" => false, "rewrite" => array( "slug" => "testable", "with_front" => true ), "query_var" => true, "supports" => array( "title", "editor", "thumbnail" ), ); register_post_type( "testable", $args ); } add_action( 'init', 'cptui_register_my_cpts' );
-
This reply was modified 7 years, 11 months ago by
J. Reason: switched blockquote to code
Not sure why, but it seems that the “resource” post type is causing the WP_Query class to end up trying to query for the “post” post type, thus why a 404 is resulting. Extremely odd, and feels beyond the control of CPTUI itself.
You can’t even point me at some helpful direction? I’m not sure what to do with that.
I would if I could, but I don’t know why it’s happening, thus I don’t know what to recommend at the moment ??
It’s happening outside of CPTUI’s code itself, since we don’t do anything directly that would affect the post preview functionality, and we don’t do any filtering regarding frontend queries.
More than willing to leave the thread open for awhile, and I’ll re-see if I can dig my way through things soon, but I didn’t have a ton of luck on that a couple days ago.
ok thanks
Dear support
we noticed the same problem on our test installation using CPT UI. Preview works as long as the custom post type is as a draft. After publishing the page we receive our 404 page.
URL as draft is: https://new.l-mobile.com/?post_type=referenzbericht&p=1046&preview=true
after publishing URL called https://new.l-mobile.com/referenzbericht/test-preview-cpt/?preview_id=1046&preview_nonce=1d4c46467c&post_format=standard&_thumbnail_id=-1
Best Regards Marc
the extra parameters on the url after publishing is going to be all WordPress core, nothing CPTUI adds.
Is “referenzbericht” essentially the same as “reference”, though a different language? I’m curious if that’s the key issue here, with something internal. Closest common denominator that I can see so far.
@lmobile, if you figure this out, please report back. I will do the same.
-
This reply was modified 7 years, 11 months ago by
- The topic ‘Preview doesn’t work on published posts, shows no results found 404’ is closed to new replies.