0

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.

5
  • It'd help if we saw the code that was outputting the list of locations. Commented Nov 29, 2020 at 15:33
  • @TonyDjukic That's the standard admin site edit categories I think.
    – Rup
    Commented Nov 29, 2020 at 16:04
  • 2
    Maybe it's the parent categories dropdown that's the problem - it's loading all of 15280 to show in the dropdown, so you're not getting as far as the pagination?
    – Rup
    Commented Nov 29, 2020 at 16:09
  • Rup, that could probably be overwritten to use a Select2 instead of a dropdown, no? Commented Nov 29, 2020 at 16:18
  • 1
    Correct. This is the standard categories/taxonomy display screen, nothing custom is being done here other than trying to show them. The parent category dropdown definitely appears to be the problem here. I am thinking perhaps I need to change the taxonomy type. Commented Nov 29, 2020 at 22:36

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.