This topic has 7 replies, 3 voices, and was last updated 8 years by Radu.

  • Author
  • #163350
     vdk
    Participant

    Hello,

    I have a question about search results.

    I was able to add a new action, so that I can choose what kind of post types wil be displayed in the search result page.

    Here’s what I did and it’s working fine:

    COPY CODE
    <span style="background-color: #e4e4ff">add_action</span><span style="background-color: #f7faff">( </span><span style="color: #008000;background-color: #f7faff;font-weight: bold">'pre_get_posts'</span><span style="background-color: #f7faff">, </span><span style="color: #000080;background-color: #f7faff;font-weight: bold">function</span><span style="background-color: #f7faff">( </span><span style="color: #660000;background-color: #f7faff">$query </span><span style="background-color: #f7faff">) {
    </span>    <span style="color: #000080;background-color: #f7faff;font-weight: bold">if</span><span style="background-color: #f7faff">( </span><span style="color: #660000;background-color: #f7faff">$query</span><span style="background-color: #f7faff">->is_main_query() && ! is_admin() && </span><span style="color: #660000;background-color: #f7faff">$query</span><span style="background-color: #f7faff">->is_search() ) {
    </span>        <span style="color: #660000;background-color: #f7faff">$query</span><span style="background-color: #f7faff">->set( </span><span style="color: #008000;background-color: #f7faff;font-weight: bold">'posts_per_page'</span><span style="background-color: #f7faff">, </span><span style="color: #0000ff;background-color: #f7faff">5 </span><span style="background-color: #f7faff">);
    </span>        <span style="color: #660000;background-color: #f7faff">$query</span><span style="background-color: #f7faff">->set(</span><span style="color: #008000;background-color: #f7faff;font-weight: bold">'post_type'</span><span style="background-color: #f7faff">, </span><span style="color: #000080;background-color: #f7faff;font-weight: bold">array</span><span style="background-color: #f7faff">( </span><span style="color: #008000;background-color: #f7faff;font-weight: bold">'post'</span><span style="background-color: #f7faff">, </span><span style="color: #008000;background-color: #f7faff;font-weight: bold">'page'</span><span style="background-color: #f7faff">, </span><span style="color: #008000;background-color: #f7faff;font-weight: bold">'advert' </span><span style="background-color: #f7faff">) );
    </span><span style="background-color: #f7faff">    }
    </span><span style="background-color: #f7faff">} );</span>

     

    However I wasn’t able to do the same thing for the ajax search.

    I saw that the search is done inside kleo_ajax_search but I wasn’t able to override it in my child theme function. Could you please help me ?

     

    Thanks

     

    #163388
     vdk
    Participant
    Not marked as solution
    #163484
     Laura
    Moderator
    Not marked as solution
    #163735
     Radu
    Moderator
    Not marked as solution
    #163740
     vdk
    Participant
    Not marked as solution
    #164049
     Radu
    Moderator
    Not marked as solution
    #164051
     vdk
    Participant
    Not marked as solution
    #164266
     Radu
    Moderator
    Not marked as solution
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?