Forum Replies Created

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter Mallander

    (@mallander)

    Hi There,

    After some deliberation about how to go about doing this, I discovered that the way to do this was using query_posts().

    This allows you to do things such as:

    // ONLY IF USING GET_PAGES() ELSEWHERE - Get the post ID's from the search to use in get_pages/get_posts
    if (have_posts() ) : while ( have_posts() ) : the_post();
        array_push($searchPosts, $post->ID);
    endwhile; else: endif;
    
    // Create the custom query params
    $pages = query_posts($query_string . '&posts_per_page=' . $postsPerPage . '&orderby=' . $sortColumn . '&order=' . $sortOrder . '&meta_key=' . $metaKey . '&offset=' . $offset);
    
    //Style to your hearts content
    foreach($pages as $page) {}

    Allowing you to customize the results and use pagination with it (well, custom pagination)

    NOTE: I’m using get_pages for a lot of my results and pagination hence why $pages = XYZ and not just directly in the query. This method could be used for the default query without the need for get_pages() but might require a bit of tweaking.

    Hope someone else finds this useful

    Mallander

    Thread Starter Mallander

    (@mallander)

    Thanks Petra,

    I’ll look more into this later, thanks for the help!

    Mallander

    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    I had to remove the line under that as well:

    $this->search_hooks();

    Otherwise it ignored the if statement you suggested to add.

    But other than that, it worked fine, thanks!

    One last question (I swear, it’s the last :P):

    Is it possible to modify the display of the results with a WP_Query? I’m trying to allow the user to change the sort_order, sort_column and posts_per_page on the search.php page with a form.

    $myQuery = new WP_Query(array(
    	"posts_per_page" => $postsPerPage,
    	"sort_column" => $sortColumn,
    	"sort_order" => $sortOrder,
    	"meta_key" => $metaKey
    ));
    if ($myQuery->have_posts() ) : while ( $myQuery->have_posts() ) : $myQuery->the_post();
    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    Finally got it to work!

    Here’s how I did it:

    Using the code you supplied earlier I added the:
    $this->options['se_use_page_search']=True;

    Then I went on to add the:
    $where = $where .” AND post_parent=61 “;

    But that only gave me the direct children of the parent, so I needed to target all of the grand-children of “61”, or in other words, the children of “61”s children.

    So, I used this:
    $where = $where ." AND (post_parent='78' OR post_parent='59' OR post_parent='68' OR post_parent='72' OR post_parent='89' OR post_parent='59' OR post_parent='65' OR post_parent='63' OR post_parent='74' OR post_parent='76' OR post_parent='70')";

    That works perfectly now, and hopefully this might come in useful for someone else.

    Thanks for all the help!

    Regards,

    Mallander

    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    I’ve just done some more testing and it is definitely to do with the structure of the products. (It’s now showing just the categories [Direct children of 61]).

    How can I change it to search children AND grandchildren of the parent?

    EDIT: Or, can I get it to target multiple post_parents at the same time in the search-everything.php

    Regards,

    Mallander

    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    This is showing no results for me. Could it be something to do with hierarchical results?

    Here is my hierarchy:

    Products <– This is the one that I was so search beneath ID = 61
    –Product Category 1 <– I want to EXCLUDE these (I can do this in the settings)
    —-Product 1.1 <– I only want to show these results (Children of 61 but no direct)
    —-Product 1.2
    –Product Category 2
    —-Product 2.1

    I believe it’s either this or the fact that I’m searching pages, but that is set in the search-everything.php and should be OK from the code you’ve supplied.

    Regards,

    Mallader

    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    Thank you very much, enjoy your weekend 🙂

    Regards,

    Chris

    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    Thanks for replying. I’m searching through pages rather than posts so I can’t add any categories to them (Plus there’s going to be around 800 pages to search through in the end, and having them all tagged will just make adding them all more difficult for the client).

    Regards,

    Chris

    Thread Starter Mallander

    (@mallander)

    Hi Petra,

    Thanks for the reply. I’ve figured out that it’s displaying using the file “search.php”. (considering the plugin uses the default search feature i should’ve known that :P)

    In regards to the broken results, the issue I was having was that I had “The Loop” running in the header.php (It was an error in my code), which meant that the search was displaying the “header.php” code for each search result, which as you can guess, caused quite the odd-looking page!

    It seems I’ve fixed that issue now but thanks for your concern!

    I do have another question though:

    Is there a way to ONLY search for pages with a specific parent? Or can I do this with a WP_Query when displaying the results?

    Regards,

    Mallander

    Thread Starter Mallander

    (@mallander)

    Sadly it’s not worked. Still getting the error.

    Thread Starter Mallander

    (@mallander)

    With the #rewriteBase, if my folder path is: Xampp/mysite/.htaccess would I put in that field: /mysite/index.php OR /index.php?

Viewing 11 replies - 1 through 11 (of 11 total)