WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom post type called 'action' messes up dashboard post search and pagination (10 posts)

  1. magicroundabout
    Member
    Posted 1 year ago #

    OK, I'm not sure what to call this: a bug possibly? Wondering if someone can help verify the behaviour and let me know if I'm just being stupid or if this needs something in either core, or possibly just the codex, fixed.

    I have a custom built theme that contains a custom post-type called "action".

    The site that this is on has a problem in the dashboard: doing a search from the posts list (for ANY post type) returns no results when you're searching for something that exists.

    Disabling the custom post type and re-running the search brings back results.

    The codex doesn't list "action" as a reserved type: http://codex.wordpress.org/Function_Reference/register_post_type

    I think this behaviour might be because the search generates a URL with a query like: /wp-admin/edit.php?s=work&post_status=all&post_type=page&action=-1&paged=1&action2=-1

    I note that if I delete '&action=-1' from the query it works again, so I'm guessing that the action form variable is generating some additional query var that's adding some condition about the action post type.

    The solution would seem to be to rename the "action" post type. But I'm wondering if anyone wants to try and verify this behaviour and help me out with some other suggestions?

    Thanks

    Ross

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    That sounds like an issue with your theme rather than a WordPress core one. Put it this way - you're the only one having this problem yet lots of people use CPTs.

  3. magicroundabout
    Member
    Posted 1 year ago #

    I'm not necessarily saying it's a problem with core. It might just be that the documentation needs updating.

    It may well be that it's my "issue with my theme" for naming my post type "action", but I'm not aware of anywhere that tells me that calling a post type "action" is a bad thing to do.

    The alternative view is that calling a post type "action" shouldn't cause this problem, in which case, something in the core is broken.

    In case you're wondering, the process I went through with diagnosis was:
    - disable plugins one-by-one (error still present with no plugins enabled)
    - change theme (error no longer present)
    - change back to my custom theme (error re-appears)
    - scan theme code for filters that might affect the query (like pre_get_posts - no filters present)
    - disable PHP includes one-by-one (each CPT and custom widget is in a PHP include)
    - eventually find that post type called "action" was the issue.

    I'm a pretty experienced dev, I've used CPT's a lot, and this is the first time I've come across this issue. But it IS an issue. I was hoping someone might validate it for me and let me know if I should raise it on trac or not.

    Thanks

    Ross

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    It may well be that it's my "issue with my theme" for naming my post type "action", but I'm not aware of anywhere that tells me that calling a post type "action" is a bad thing to do.

    That could well be the problem. Have you tried using something less generic?

  5. magicroundabout
    Member
    Posted 1 year ago #

    Well, yes. I'm going to change my code to do that. But my point is that if "action" isn't listed in the codex as an identifier that you shouldn't use (and, as far as I can tell, it's not) then I should be able to use it, and I can't.

    So either:
    - I'm not looking in the right place in the codex; OR
    - codex needs updating to list "action" as an invalid post type name; OR
    - codex is right, I should be able to use it, and core needs fixing.

    Could use:
    a) validation that calling a post type "action" breaks things the dashboard post search
    b) some direction on how to get either codex or core fixed

    Thanks

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    my point is that if "action" isn't listed in the codex as an identifier that you shouldn't use

    Neither is it mentioned that you shouldn't prefix your functions with wp_. Or that you shouldn't use post, page or attachment as names for your CPTs. It would be a practical impossibility to try and list every reserved term in an application the size of WordPress.

  7. magicroundabout
    Member
    Posted 1 year ago #

    Neither is it mentioned...that you shouldn't use post, page or attachment as names for your CPTs.

    Well, I'm gonna have to disagree with that statement: http://codex.wordpress.org/Function_Reference/register_post_type

    Look, I spent about 2 hours debugging this last night. I've taken time to post a detailed explanation here this afternoon. I'm just trying to save someone else the hassle of having to do the same work again.

    If you think this is a "reserved term" and not an issue with the core can we just add it to the list? Can I submit a change to the codex somehow? What should I do?

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    If you have found that action is a reserved word, then please feel free to update the Codex page yourself. The Codex is a community project. Everyone is a potential editor.

  9. magicroundabout
    Member
    Posted 1 year ago #

    Ah yes. I was already logged in to forums and didn't realise I had to log in again to edit the codex. I was looking for an edit button that wasn't there. Done!

    Thanks for your help esmi!

    Ross

  10. magicroundabout
    Member
    Posted 1 year ago #

    Marking as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic