I am building a segmented search (by post type) with the ability to filter to a specific post type and realized pages were not publicly queryable. What I know I can do is the following:

function fix_page_query() {
    if ( post_type_exists( 'page' ) ) {
        global $wp_post_types;
        $wp_post_types['page']->publicly_queryable = true;
add_action( 'init', 'fix_page_query', 1 );

which does allow them to use post_type as a query var, but are there any shortcomings to doing this? Was there a specific reason they are not by default? I did see this ticket about the subject, but could not decipher a clear answer. Thanks!

  • I think Sergey answered your question there. – Brian Fegter Oct 3 '12 at 15:10
  • The "clear answer" was the patch he provided. – Liana Mir Oct 3 '12 at 15:41
  • @BrianFegter Sergey said what I knew (you can't publicly query them by post_type in this case because publicly_queryable is false), but I'm asking if there is a shortcoming to adding this in (as the action I have above does). Again, I am looking for clarity on the subject, so saying "Sergey answered your question here" doesn't help me as that is the confusing part. – Zach Oct 3 '12 at 16:27
  • It is confusing, but I think his answer is appropriate though the logic is extremely confusing in core. – Brian Fegter Oct 3 '12 at 18:27
  • 1
    Correct. :) It won't affect anything negatively from my view. – Brian Fegter Oct 3 '12 at 18:48

Just to close this one out - you can set Pages to be publicly_queryable using the function provided above.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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