{"id":4432042,"date":"2013-12-19T22:37:03","date_gmt":"2013-12-19T22:37:03","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/custom-qp\/"},"modified":"2016-08-21T13:42:19","modified_gmt":"2016-08-21T13:42:19","slug":"custom-qp","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/custom-qp\/","title":{"rendered":"Custom QP"},"content":{"rendered":"<p>I have a custom query set up for a website that&#8217;s ordering the posts by the 2nd word of the post title (they are names, so it&#8217;s ordering by last names). My custom query is working perfectly in wordpress 3.7, but in 3.8 it does absolutely nothing. This is the code I wrote:<\/p>\n<pre><code>function custom_get_posts($query) {\n\n\tif (is_category()) {\n\n\t\tglobal $wpdb;\n\t\tglobal $post;\n\n\t\tif(is_category(14)) {\n\n\t\t\t$querystr = &quot;\n\t\t\tSELECT DISTINCT wposts.ID\n\t\t\tFROM $wpdb-&gt;posts wposts\n\t\t\t\tLEFT JOIN $wpdb-&gt;postmeta wpostmeta ON wposts.ID = wpostmeta.post_id\n\t\t\t\tLEFT JOIN $wpdb-&gt;term_relationships ON (wposts.ID = $wpdb-&gt;term_relationships.object_id)\n\t\t\t\tLEFT JOIN $wpdb-&gt;term_taxonomy ON ($wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id)\n\t\t\tWHERE $wpdb-&gt;term_taxonomy.term_id IN (&#039;14&#039;)\n\t\t\t\tAND wposts.post_status=&#039;publish&#039;\n\t\t\tORDER BY SUBSTR(LTRIM(wposts.post_title), LOCATE(&#039; &#039;, LTRIM(wposts.post_title))) ASC\n\t\t\t&quot;;\n\n\t\t\t$pageposts = $wpdb-&gt;get_results($querystr, OBJECT);\n\n\t\t\t$pageposts_arr = array();\n\t\t\tforeach ($pageposts as $pagepost) {\n\t\t\t\tarray_push($pageposts_arr, $pagepost-&gt;ID);\n\t\t\t}\n\n\t\t\tif($query-&gt;is_main_query()) {\n\t\t\t\t$query-&gt;query_vars[&#039;post__in&#039;] = $pageposts_arr;\n\t\t\t\t$query-&gt;query_vars[&#039;orderby&#039;] = &#039;post__in&#039;;\n\t\t\t}\n\n\t\t} elseif (is_category(24)) {\n\t\t\tif($query-&gt;is_main_query()) {\n\t\t\t\t$query-&gt;query_vars[&#039;orderby&#039;] = &#039;modified&#039;;\n\t\t\t}\n\t\t}\n\n\t}\n\n\treturn $query;\n}\nadd_filter(&#039;pre_get_posts&#039;, &#039;custom_get_posts&#039;);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-4432042","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4432042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4432042\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4432042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}