Question

I am working with a WordPress website which will support the creation of listings. These listings can be associated with a geographical area, specifically, an address in a suburb in Australia. I created a simple PHP script which I run from the command line to add in my terms into my custom taxonomy.

However, when I attempt to view the locations I am adding into the site, I get an error about memory being exhausted.

enter image description here

This error appears while trying to view the list of locations. All in all, I am trying to add in 15280 Australian suburbs into the taxonomy.

I currently have the memory limit in my wp-config.php file set to 512MB, I don't want to increase it because it feels like a hack. There must be something else going on here, as I would have thought pagination would mean the queries are actually not getting much data back at all for each page.

Était-ce utile?

La solution

I solved this issue after Rup in one of the comments pointed out that the parent categories dropdown was most likely the culprit. Sure enough, that was the issue. It appears WordPress was attempting to populate the dropdown with 15,000 items which were causing an excessive query to be made to retrieve those items.

The simple fix in my instance was making my custom taxonomy, non-hierarchical. My locations were not using any parent/child relationship, so the structure could be flat and just standalone location terms.

$args = [
        "label" => __( "Locations", "propertynet" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => false,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'location', 'with_front' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "rest_base" => "location",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => false,
];

Setting the configuration property on the taxonomy arguments to false is what made WordPress be able to work with my large amount of terms: "hierarchical" => false - this poses a larger problem if you're wanting your terms to be hierarchical, which seems would require re-implementing the parent category dropdown to support AJAX loading and work similarly to how pagination works normally on this screen.

Hopefully, this helps anyone else who encounters the same problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top