Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Complex template query

Viewing 8 posts - 1 through 8 (of 8 total)
  • Trisha Miller
    #13177

    Greetings,

    The shortcode approach to display results works, but does not display anything other than the title of the resulting content and I need to display an excerpt and some custom meta data.

    When I used a template with a custom loop (necessary because this is a Custom Post Type that also has custom fields/meta data), the S&P results displays the results formatted correctly but the search filters don’t work, ALL results are shown regardless of what filters are checked or unchecked.

    I do understand your instructions on ensuring that there is NO loop in the custom template file, however we need to have the Page content (a featured image and some explanatory text) at the top of the page, then a custom section below that initially displays ALL of the custom posts, allowing the site visitor to filter the results.

    I tried using a custom search template (copying search.php to new search-deals.php) and then used “include” to include that template at the spot in the custom Page template where I want the results to display, and changed (under Display Results) from ‘using a shortcode’ to ‘using and archive page” and set the template file to search-deals.php, but then it only shows the page content a second time.

    I also created a custom ‘results’ page using the instructions found in the documentation, and put it in a folder in my Theme (/search-filter/results-deals.php) and in there I put the custom meta definitions and the custom formatting that I want – no luck, it still only displays the Page content, not the search results (in any format).

    So I’m sure I’m just missing something glaringly obvious, but how do I accomplish what I need?

    Here’s what I need:
    A Page that displays it’s featured image and some content, below that a custom query for all posts in a Custom Post Type and to it’s left a sidebar with search filters. The initial and filtered results should display a title, and below that some of the (custom) meta data entered for each Post in the Custom Post type.

    Shortcode works on the filtering perfectly but only displays the post title
    Using a custom template – with or without a loop only shows Page content

    Hoping someone can help!

    Ross Moderator
    #13180

    Hey there

    If you are using “as archive” mode, and you are running an unrelated custom query in the template, then you must reset the query after you have run it –

    http://wordpress.stackexchange.com/questions/144343/wp-reset-postdata-or-wp-reset-query-after-a-custom-loop

    I think you need wp_reset_query in this case.

    If you want to use the shortcode method, then create a new page/post, and paste in the results shortcode in the regular post editor..

    If you are not happy with the way this displays, you must customise template according to the instructions here:

    http://www.designsandcode.com/wordpress-plugins/search-filter-pro/docs/#docs-new-ajax

    Customising the template when using archive Vs shortcode method is different.

    Thanks

    Trisha Miller
    #13183

    Making some progress, but still having trouble.

    I did finally get the custom results template to work – I misunderstood the instructions and didn’t realize that the custom results template MUST stay named ‘results.php’ – unlike when one creates custom template files by post type (e.g. single-something.php).

    However while it does display the results in the correct format, the meta data is not showing up – previously in my custom loop I had to use a custom query (get_posts) to isolate the custom post type and use some of the meta data in the query, then used

    foreach ( $myposts as $post ) : setup_postdata( $post );

    Followed by my custom meta data variable definitions, which I could then use in structuring the format.

    Since I cannot use my custom query, the ‘loop’ is ignoring my meta data variables. How can I incorporate my custom fields if I cannot write the query for the loop?

    Trisha Miller
    #13184

    Well I’ve made more progress, but unhappy with how I have to go about this, and the solution creates headaches with the formatting of date fields.

    First, I was forced to use the Advanced Custom Fields plugin to be able to access the custom meta data. This makes me unhappy because I dislike using plugins where they shouldn’t be necessary – get_post_meta is very simple to use to access Post Meta Data, I shouldn’t need yet another plugin just to get to it.

    Further, the site hosting company’s version of PHP is (sadly) still pre-5.3, so I cannot use the simple DateTime functions to convert the stored date to a nice pretty format – I can do it, but it means several more lines of code for each stored date…..again, this shouldn’t be necessary and wouldn’t be if I were able to use the get_post_meta – that makes it easy to convert the date format.

    SO I guess rather than asking for help solving my initial problem, to which I’ve found a very clunky workaround, I would respectfully suggest an easier way to access post meta data in the results so it can be formatted, including custom meta data.

    Trisha Miller
    #13185

    Thanks Ross – I didn’t refresh this page so I only just now saw your response after I’ve posted again.

    I appreciate the very prompt reply, and I did wind up following your suggestion – I’ll keep tweaking it until I get it just right.

    Your plugin is really great, it would be lovely if you could add some options to the settings to make it easier to access any custom meta data on posts returned in the results. I am NOT a coder, but have learned enough to paste all of this together to get it working, but it would be nice if there was an easier way, and of course for folks with far less experience than I have (and I am by no means an expert) it would probably make this plugin even more valuable.

    Right now I’m down to just a clunky workaround on the date formatting issue – all else is resolved.

    thanks again,
    Trisha

    Ross Moderator
    #13188

    Hey Trisha

    Thanks for the messages & updates. Just so you know, there should be absolutely no reason get_post_meta isn’t working – I’ve used & tested this for both display types (shortcode and archive) without any problems.

    The plugin simply creates queries, and uses templates to iterate through them – there is nothing special about these queries, you should be able to use all standard WP functionality.

    I’m not sure what the issue would be, but I would double check the key you are using to access the meta data.

    To do a dump of all the meta data of a post, just add this inside the loop:

    <?php
        $meta = get_post_meta( get_the_ID() );
        echo "<pre>";
        var_dump($meta);
        echo "</pre>";
    ?>

    Modified from – http://codex.wordpress.org/Function_Reference/get_post_meta

    You should now be able to see all the meta data associated with a post – and hopefully find the correct key for what you need.

    Thanks

    Trisha Miller
    #13234

    Thanks for the reply Ross……I think the problem is that previously (before using the SP plugin or making any attempt to filter the results), I used the get_posts style of query in order to compare one of the meta keys holding a (expiration) date to the current date, and to not display results for those posts where the meta-value date had passed…..then I used a foreach loop and setup_postdata to access all the meta data. That query worked perfectly – returned results unless the date had passed. All was great until I was asked to add some live filtering of the results.

    And I did figure out (rather easily) how to use the meta data to setup the same comparison in the “advanced” setting in the SP plugin, so the SP query does weed out those posts whose meta date has passed, so all was good there – I did get the expected posts returned. The only thing was that the “results.php” file that displays the results has a custom query variable ($query->the_post) most likely using wp_query rather than get_posts, and that does not seem to work with setup_postdata – because as near as I can tell, setup_postdata only seems to work with ‘foreach’, not ‘while’ loops….and foreach seems only to work with get_posts.

    As mentioned, I’m not a coder, so there’s likely a better way to do what I’m trying to do, but it took me many, many days of research and testing to get my (old) query just right, it just wasn’t further filterable without your plugin.

    NOW I do have everything working just great, but using the ACF “get_field” and “the_field” instead of get_post_meta – formatting dates is working great too…..so really I’m a pretty happy camper today…..I just wish I was more skilled with programming, I might have found a cleaner way….

    But I really do love this plugin…..it’s very impressive. I’m off to give the free version (which I tested first) a great review on the repository and give a shout-out to the paid version, which is even better. I always do that when I find a worthy plugin. 🙂

    Ross Moderator
    #13246

    Glad you got it working and thanks for the kind words 🙂

    Best

Viewing 8 posts - 1 through 8 (of 8 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.