Odd Issue with CustomPress: (Most) Links Going to Archive Instead of Post

So, the title pretty much says it all. Links are going to the archive for the custom post type instead of going to the post itself. Oddly, this is occurring only for one of the custom post types enabled on this site and it doesn't happen to the most recent post of that type. I've already rebuilt permalinks, cleared all caches (local, server, CDN), and checked for updates or issues in the theme in use. Thus far, I've had no luck in figuring out what is causing the odd issue. I've granted support access through WPMU DEV Dashboard.

  • Rupok

    Hi Zyniker,

    So sorry for the inconvenience you are having. This is really weird and should not happen.

    Thanks for granting Support Access. I logged in and found that there are 5 custom post types registered with CustomPress. Can you please tell us which custom post type to check? Also, please let us know on which site should I check? I found that you have one main site and one subsite.

    Besides, can you please provide a link of a post of that custom post type which is having this issue?

    Please let us know all these details. We will jump in as soon as you confirm.

    Have a nice day. Cheers!

  • Zyniker

    Hello Rupok ,

    I think I may have discovered the issue. It looks like there was some weird interplay between/among Redirection, CustomPress, and a code snippet I use for naming a handful of custom post types. As best I can tell, it looks like the following code snippet is misbehaving:

    add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 ); // Grabs the inserted post data so you can modify it.
    function modify_post_title( $data ){
    	if($data['post_type'] == 'remark' || $data['post_type'] == 'quote' || $data['post_type'] == 'share'){
    		$id = get_the_ID();
    		$new_title = get_the_time( 'Y-m(M)-d(D)—HiT', $id );
    		$new_slug = get_the_time( 'Y-m-d-HiT', $id );
    		$data['post_title'] =  $new_title ;
    		$data['post_name'] = strtolower($new_slug); //Updates the post title to your new title.
    	return $data;

    What this code snippet should do (and does, in fact, do) is rename the specified custom post types based on the patter in the code (essentially, it just sets the title to the date and time so that the custom post types will not require a manually set title). However, what the code is also doing that it should not do is updating the post title (and also the slug) whenever a post is simply modified.

    From my testing, it looks like what happened was the custom post types in question has an additional category added to them, en masse, and this 'update' resulted in all of them having the same slug. Consequently, it wasn't actually the archive for the custom post type that was being displayed, but a collection of custom posts that all had the same slug (it just so happened that the archive and the collection were indistinguishable as they contained the same set of posts).

    After a bit of checking for broken links, I was able to set up a handful of redirects (using Redirection) that address the issues. It looks like the problem was not with CustomPress.

    I'm still not sure why the code, included supra, is misbehaving, though.

  • Kasia Swiderska

    Hello ,

    However, what the code is also doing that it should not do is updating the post title (and also the slug) whenever a post is simply modified.

    According to codex https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data

    A filter hook called by the wp_insert_post function prior to inserting into or updating the database.

    And wp_insert_post is called when "Insert or update a post."
    So when you update post your function will be also called. And that if only checks if post_type if one of three types. So if you updated one of those post and they were of that types then that function was fired.
    Here is more about hooks on post creation https://ruslanbes.com/devblog/2014/01/01/wordpress-hooks-on-post-creation/

    kind regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.