# Slow query

**URL:** <https://www.phphelp.com/t/slow-query/20895>\
**Category:** Beginners - Learning PHP\
**Created:** [August 20, 2013, 3:58pm UTC](https://www.phphelp.com/t/slow-query/20895 "2013-08-20T15:58:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JAsonA](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@JAsonA](https://www.phphelp.com/u/JAsonA)\
**Post date:** [August 20, 2013, 3:58pm UTC](https://www.phphelp.com/t/slow-query/20895/1 "2013-08-20T15:58:35Z")

</div>

I’m using a plugin in WordPress called Business Directory Plugin to grab information from the database through a template. The query pulls all 400 records and displays their name, address, phone number and a short description. This seems to take 8 seconds to gather and show the information. Is there any way I could speed up and consolidate the following script:

[php]\<?php $listing\_id = get\_the\_ID(); ?\>

\<?php echo $title; ?\> | \<?php $arr = get\_post\_meta( get\_the\_ID(), ‘\_wpbdp[fields][10]’, true );  
foreach ( $arr as $item) :  
echo “$item”;  
endforeach; ?\> \<?php $field = wpbdp\_get\_form\_field( 23 );  
echo $field-\>value( $listing\_id ); ?\> | \<?php $field = wpbdp\_get\_form\_field( 6 );  
echo $field-\>value( $listing\_id ); ?\> | \<?php $field = wpbdp\_get\_form\_field( 53 );  
echo $field-\>value( $listing\_id ); ?\>[/php]

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [August 20, 2013, 6:00pm UTC](https://www.phphelp.com/t/slow-query/20895/2 "2013-08-20T18:00:39Z")

</div>

Is the query slow or is it the part that writes the output to the screen?

---

<div class="post-metadata">

**Author:** ![JAsonA](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@JAsonA](https://www.phphelp.com/u/JAsonA)\
**Post date:** [August 20, 2013, 6:12pm UTC](https://www.phphelp.com/t/slow-query/20895/3 "2013-08-20T18:12:28Z")

</div>

To tell you the truth i’m not sure. I put a page loader on it, but it doesn’t come in until the query is finished and the page starts to load.

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [August 20, 2013, 6:16pm UTC](https://www.phphelp.com/t/slow-query/20895/4 "2013-08-20T18:16:44Z")

</div>

It’s hard to even tell you where to look, I don’t see the SQL calls to the database, the database structure and indexes. A lot of information is missing to tell you where the slowdown might be.

---

<div class="post-metadata">

**Author:** ![JAsonA](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@JAsonA](https://www.phphelp.com/u/JAsonA)\
**Post date:** [August 20, 2013, 6:43pm UTC](https://www.phphelp.com/t/slow-query/20895/5 "2013-08-20T18:43:50Z")

</div>

well, let’s just look at the code… is there something in that which I can consolidate down?

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [August 20, 2013, 7:35pm UTC](https://www.phphelp.com/t/slow-query/20895/6 "2013-08-20T19:35:17Z")

</div>

The topic of this post said “Slow Query”, but you didn’t show us the query.

The code is fine, you can probably remove some context switching with all the open and closed PHP tags, but you’re talking fractions of milli-seconds.

You have a lot of functions being called

wpbdp\_get\_form\_field  
get\_post\_meta  
get\_the\_ID

I don’t know what those functions do, no code for them.

It’s really hard to help without all the details, I’m not a WordPress so I’m not familiar with their functions.
