{"id":2643,"date":"2026-10-20T08:35:23","date_gmt":"2026-10-20T07:35:23","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/query-listings-by-category\/"},"modified":"2026-10-20T08:40:20","modified_gmt":"2026-10-20T07:40:20","slug":"query-listings-by-category","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/query-listings-by-category\/","title":{"rendered":"How to query GeoDirectory listings by category ID"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">GeoDirectory categories are normal WordPress taxonomy terms. Each post type has its own category taxonomy, named after the post type with category on the end: Places use <code>gd_placecategory<\/code>, and a post type called <code>gd_event<\/code> uses <code>gd_eventcategory<\/code>. That means a standard <code>tax_query<\/code> works and you don&#8217;t need a custom join.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To find a category ID, go to Places > Categories, hover over the category and look for <code>tag_ID=<\/code> in the edit link.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">With WP_Query<\/h2>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">$query = new WP_Query( array(\n\t&#039;post_type&#039;      =&gt; &#039;gd_place&#039;,\n\t&#039;post_status&#039;    =&gt; &#039;publish&#039;,\n\t&#039;posts_per_page&#039; =&gt; 20, \/\/ -1 for all\n\t&#039;tax_query&#039;      =&gt; array(\n\t\tarray(\n\t\t\t&#039;taxonomy&#039;         =&gt; &#039;gd_placecategory&#039;,\n\t\t\t&#039;field&#039;            =&gt; &#039;term_id&#039;,\n\t\t\t&#039;terms&#039;            =&gt; array( 85 ),\n\t\t\t&#039;include_children&#039; =&gt; true,\n\t\t),\n\t),\n) );\n\nif ( $query-&gt;have_posts() ) {\n\twhile ( $query-&gt;have_posts() ) {\n\t\t$query-&gt;the_post();\n\t\techo &#039;&lt;a href=&quot;&#039; . esc_url( get_permalink() ) . &#039;&quot;&gt;&#039; . esc_html( get_the_title() ) . &#039;&lt;\/a&gt;&lt;br&gt;&#039;;\n\t}\n\twp_reset_postdata();\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To read a GeoDirectory field inside the loop, use <code>geodir_get_post_meta( get_the_ID(), &#039;phone&#039;, true )<\/code>, where the second argument is the field key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">With geodir_get_widget_listings()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the function behind GD > Listings. It reads from the GeoDirectory listing table, so every result already has the custom field values, and it accepts GeoDirectory sort values such as az and latest.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">$listings = geodir_get_widget_listings( array(\n\t&#039;post_type&#039;      =&gt; &#039;gd_place&#039;,\n\t&#039;posts_per_page&#039; =&gt; 20,\n\t&#039;order_by&#039;       =&gt; &#039;az&#039;,\n\t&#039;tax_query&#039;      =&gt; array(\n\t\tarray(\n\t\t\t&#039;taxonomy&#039; =&gt; &#039;gd_placecategory&#039;,\n\t\t\t&#039;field&#039;    =&gt; &#039;id&#039;,\n\t\t\t&#039;terms&#039;    =&gt; array( 85 ),\n\t\t),\n\t),\n) );\n\nforeach ( $listings as $listing ) {\n\techo esc_html( $listing-&gt;post_title ) . &#039;&lt;br&gt;&#039;;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">With the REST API<\/h2>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-bash\">https:\/\/example.com\/wp-json\/geodir\/v2\/places\/?gd_placecategory=85<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here places is the post type&#8217;s slug. See <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/api\/endpoints\/\">Endpoints<\/a> and <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/how-tos\/filter-search-results-from-the-geodirectory-rest-api\/\">Filter search results from the GeoDirectory REST API<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Without code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To display the listings rather than process them, the GD > Listings widget has a Categories filter: <code>&#091;gd_listings post_type=&quot;gd_place&quot; category=&quot;85&quot;&#093;<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GeoDirectory categories are normal WordPress taxonomy terms. Each post type has its own category taxonomy, named after the post type with category on the end: Places use gd_placecategory, and a post type called gd_event uses gd_eventcategory. That means a standard tax_query works and you don&#8217;t need a custom join. To find a category ID, go [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-2643","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=2643"}],"version-history":[{"count":1,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2643\/revisions"}],"predecessor-version":[{"id":2800,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2643\/revisions\/2800"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2643"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2643"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}