Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Custom Post Type Interfering with Pages

         

lexipixel

8:18 pm on Mar 11, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wrote a plugin and everything works as expected, except when the plugin is activated, all the pages on the site, (`wp_post`.`post_type` = 'page'), get a 404.

(Yes, I've tried resaving permalinks settings)

My plugin creates a custom post type "mycustomtype", which is just a lot of parent/child related pages -- no need for "categories" or "tags" or any other taxonomy.

The plugin does not create a custom taxonomy.

The strange behavior is:

1. Pages are found in search. If you click the link, it 404's. (The URL for the page should be valid -- it works when the plugin is deactivated.

2. I installed Query Monitory plugin, and queries for pages include the condition:

AND wp_posts.post_type = 'mycustomtype'

If someone is fluent in custom post types, taxonomy, etc.. I will post whatever code you want to see.

Any ideas ?

not2easy

10:44 pm on Mar 11, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If it works when the plugin is deactivated, why not just deactivate it? Or I missed something..

lexipixel

5:05 am on Mar 12, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If it works when the plugin is deactivated, why not just deactivate it? Or I missed something..
-not2easy


As I said, I wrote a plugin, (because I need it), and need it activated.

Here's the scenario-

1. We have "articles" (a knowledge base of Wordpress PAGES arranged in parent/child hierarchy), e.g. -

KB 
|__ Stuff about Cats
| |_ Cat Article #1
| |_ Cat Article #2
| |_ Cat Article #3
|
|__ Stuff about Dogs
| |_ Dog Article #1
| |_ Dog Article #2
|
|__ Stuff about Birds
| |_ Bird Article #1
|
|__ Other Stuff
| |_ Other Stuff #1
| |_ Other Stuff #2


Then we have a database of 25,000 records of "Widget Info".

The 25k "PAGES" of "Widget Info" which are also arranged in Parent/Child hierarchy, use a custom post type, (set to hierarchal, with page attributes, etc)...

e.g. --

Widget Info
|
|__ Section 1 - Red Widget
| |__ Red Widget Info #1
| |__ Red Widget Info #2
| |__ Red Widget Info #3
|
|__ Section 2 - Blue Widgets
| |__ Blue Widget Category 1
| | |__ Blue Widget Classification 222
| | |__ Blue Widget Info #4762
| | |__ Blue Widget Sub-class #4762.5
| | | |__ Blue Widget Info #4762.5.1
| | | |__ Blue Widget Info #4762.5.2
| | |__ Blue Widget Info #4763
| |__ Blue Widget Info #4764
| |__ Blue Widget Info #4765
|
|__ Section 3 - Yellow Widgets
| |__ Yellow Widget Info #24641
| |__ Yellow Widget Info #24642


The "kb articles" are created manually, in no particular order, and can be edited, updated, moved around, etc...

The "widget data" is updated via import, (I "reserved" a block of 35,000 WordPress ID's to hold the data by creating drafts from ID #5000 - ID #40000 --- this is so the ID's never change and I can easily update and maintain).



With all that said, I have a feeling my problem is on one of three areas:

1. My register_post_type() setings.

2. The fact that I haveno custom taxonomy.

3. an "init issue" -- maybe order plugin files are loaded...


The "KB" articles work fine, appear as expected --- but throw 404s when the plugin is active.

The "Widget Info" data only shows when plugin is active.

not2easy

12:24 pm on Mar 12, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Have you looked into the functions.php file to see the current workings and maybe spot where it can be improved for your changes? I would look into options for how "register_post_type()" might be utilized.

I have not done any customization like what you are working on, but WP offers documentation on customizing that might be useful: [wordpress.org...]

lexipixel

7:05 pm on Mar 12, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...a suggestion to "RTFM" and link to unrelated "presentation related" Customization is less than helpful.

lexipixel

4:23 am on Apr 2, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I found the problem, maybe posting the solution here will help someone else --

The problem two-fold:

1. my plugin was doing a rewrite to "/" which affected all pages except the home page ---

'rewrite' => array('slug' => '/','with_front' => false),


I used this because I believed the "root" of the entire hierarchy would be a link on the home page -- that by just having that link, the others would inherit the "path". They did, but so did every other URL in the site. Instead I used the following rewrite for my "Widget"(Custom Post Type)pages --

'rewrite' => array('slug' => 'widget-info','with_front' => false )


2. Under Dashboard > Settings > Permalinks > I had set the URLs to use: Custom Structure: https://www.example.com/%category%/%postname%/ ...but in a parent/child page hierarchy, there are no "categories". To get a URL like: https://example.com/things/trees/pine-trees you only need to use the %postname% slug variable -- Wordpress will build the URL using the base URL, ancestors of the page and the page's slug, (in this case "pine-trees").

.

[edited by: not2easy at 11:10 am (utc) on Apr 2, 2024]
[edit reason] de-linked for readability [/edit]