WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Custom Field Template] cftsearch question (5 posts)

  1. yorokobi
    Member
    Posted 3 years ago #

    Looking for a way to code the ctfsearch into a theme's php page. I want it to appear above the output of theloop, so users can use the search to filter the posts.

    Is there a php function that I can call that will behave as if there was a [cftsearch] on the page content?

  2. Hiroaki Miyashita
    Member
    Posted 3 years ago #

    Use the following way:

    <?php
    echo do_shortcode('[cftsearch]');
    ?>
  3. yorokobi
    Member
    Posted 3 years ago #

    Perfect, but I have another question - I have used sort=menu_order and orderby=ASC which works find, unless I use the cftsearch.

    Picking through the code I found that if I changed $_REQUEST['order'] = DESC to ASC in this part of your plugin:

    function custom_field_template_posts_orderby($sql) {
    		global $wpdb;
    
    		if ( empty($_REQUEST['order']) || ((strtoupper($_REQUEST['order']) != 'ASC') && (strtoupper($_REQUEST['order']) != 'DESC')) )
    			$_REQUEST['order'] = 'DESC';

    Then I get ASC order, so what do I need to do to NOT change your code, but satisfy the conditional statement so I get the ASC order I want?

  4. yorokobi
    Member
    Posted 3 years ago #

    BTW, there is a mismatched </p> tag on line 3229 causing validation failure, I simply deleted it.

  5. yorokobi
    Member
    Posted 3 years ago #

    Ok I figured it out. First I don't need ASC anymore because I re-ordered my posts when I found that the next-post and last-post links were working backwards, but I still needed to impose orderby=menu_order.

    For normal post listing and search I have added orderby=menu_order to the query string right before "theloop" but what I didn't know was how to add it to the CFTSEARCH.

    Turns out it's easy. All I had to do was add:
    <input type="hidden" name="orderby" value="menu_order" /> to the "FORMAT" I was using for the search form.

Topic Closed

This topic has been closed to new replies.

About this Topic