• Hi, I’m trying to filter search results to pages of a specific parent page (id=16). I’ve been told i can have a hidden field, like this:
    <input type="hidden" name="parent" value="16" />
    or
    <input type="hidden" name="child_of" value="16" />

    This does add this to the end of the url:
    ?s=upload&parent=16 or
    ?s=upload&child_of=16

    But I’m still getting all pages as results. What am i doing wrong? here’s my form code (the input field is in the bottom)

    <form class="el6 x-search" data-x-search="{&quot;search&quot;:true}" action="https://www2.filecamp.com/" method="get">
    
      <label class="visually-hidden" for="s-el6">Search</label>
    
      <input id="s-el6" class="x-search-input" type="search" name="s" tabindex="" placeholder="Search the Knowledge Base" style="outline: none;">
      <button class="x-search-btn x-search-btn-submit" type="button" data-x-search-submit="" tabindex=""><span class="visually-hidden">Submit</span><svg xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-1 -1 25 25"><circle fill="none" stroke-width="1" stroke-linecap="square" stroke-miterlimit="10" cx="10" cy="10" r="9" stroke-linejoin="miter"></circle><line fill="none" stroke-width="1" stroke-linecap="square" stroke-miterlimit="10" x1="22" y1="22" x2="16.4" y2="16.4" stroke-linejoin="miter"></line></svg></button>
      <button class="x-search-btn x-search-btn-clear" type="button" data-x-search-clear="" tabindex=""><span class="visually-hidden">Clear</span><svg xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-1 -1 25 25"><line fill="none" stroke-width="1" stroke-linecap="square" stroke-miterlimit="10" x1="19" y1="5" x2="5" y2="19" stroke-linejoin="miter"></line><line fill="none" stroke-width="1" stroke-linecap="square" stroke-miterlimit="10" x1="19" y1="19" x2="5" y2="5" stroke-linejoin="miter"></line></svg></button>
    <input type="hidden" name="parent" value="16" />
    </form>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    You’re on the right track, the parameter is just called post_parent.

    Thread Starter Johan SP

    (@therealjohan)

    I simplified it a bit and now have this:

    <form role="search" method="get" id="searchform" class="searchform" action="https://www2.filecamp.com/">
    <div>
    <label class="screen-reader-text" for="s">Search for:</label>
    <input type="text" value="" name="s" id="s" />
    <input type="hidden" name="post_parent" value="16" />
    <button type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>

    The url i get after searching is this: https://www2.filecamp.com/?s=upload&post_parent=16

    Looking at it, I would think that it would only filter pages pages that have the parent page with the ID=16, but I’m getting all pages as a result.

    Where am I going wrong?

    Plugin Author Mikko Saari

    (@msaari)

    Looks like some kind of WordPress feature –?Relevanssi is not seeing the post_parent parameter, even if you set it. WordPress just doesn’t pass the parameter to Relevanssi. If I check at pre_get_posts, ie. before Relevanssi, the parameter is also missing.

    This needs to circumvented, like this:

    add_action('pre_get_posts', 'rlv_set_post_parent');
    function rlv_set_post_parent($query) {
    	if (isset($_REQUEST['post_parent'])) $query->set('post_parent', $_REQUEST['post_parent']);
    }

    Even if WordPress is not passing the parameter, you can always read it directly from the request.

    Hey, is there a way to get all the children posts under the id? It seems that with this
    <input type="hidden" name="post_parent" value="16" />
    I can only get the direct children posts.

    Or is there a way to use multiple parent id’s or show posts with a certain tag?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Filter only pages of a parent page (child of)’ is closed to new replies.