I have a category page as below:

enter image description here

and when a category is clicked, using the following code

$sql_categories = $wpdb->prepare ("SELECT * FROM ".$wpdb->prefix."wtd_art_categories WHERE Parent = %d ORDER BY Id", $_GET['c']);
$get_categories = $wpdb->get_results( $sql_categories );

it queries sub categories and then I display on the same page. (Example Shapes clicked):

enter image description here

Since each time there is a query, I thought this is causing the delay, and I used a session variable to keep the $wpdb->get_results , however still it is not fast as I expected.

What kind of trick can I use to increase speed of navigation inside these categories ?

Edit: wtd_art_categories table: (Data is dummy) enter image description here

  • Can you provide details of the custom table [prefix]_wtd_art_categories? What columns are present, and do you have indexes on the Parent and Id columns?
    – joetek
    May 11, 2017 at 13:40
  • Are you aware of custom taxonomies?
    – Tom J Nowell
    May 11, 2017 at 13:42
  • @joetek , I updated my question, the data is dummy, but rows and column structure is like that. And at the moment it is only 7 lines of data.
    – HOY
    May 11, 2017 at 13:49
  • @TomJNowell I have heard them , but they never came to my mind while I am developing a custom plugin. I don't have any practice on them, so I am not quite sure how to use them. So can I use them? , and will there be a significant increase of speed ?
    – HOY
    May 11, 2017 at 13:54
  • I would expect there would be an increase in speed, and they'll be easier to work with than raw SQL. I won't cover how to use them though as there's thousands of tutorials elsewhere that do a much better job
    – Tom J Nowell
    May 11, 2017 at 16:34


Your Answer

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