• Resolved Mushlih Almubarak

    (@mushlih)


    1. Can I create two search forms?
    I don’t mean to put the search form in 2 places, but I want to make 2 searches with different settings.
    2. Can I put the search form on the category and tag pages? And the search form in categories and tags page only searching for articles in that taxonomy.
    Can it?

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    1. Unfortunately multiple search forms with different configurations are only available in the Pro version of the plugin.

    2. There is no option, but you can try this custom code:

    add_action('asl_layout_in_form', 'asl_layout_in_form_archive_input', 10);
    function asl_layout_in_form_archive_input() {
        $taxonomies = 'category, post_tag, product_cat'; // Enter the taxonomy names here
    
        // --- DO NOT CHANGE ANYTHING BELOW THIS LINE ---
        $taxonomies = explode(',', $taxonomies);
        foreach ( $taxonomies as $k => &$tax )
            $tax = trim($tax);
        if (
            ( in_array('category', $taxonomies) && is_category() ) ||
            ( in_array('post_tag', $taxonomies) && is_tag() ) ||
            is_tax($taxonomies)
        ) {
            $obj = get_queried_object();
            if ( isset($obj, $obj->term_id) ) {
                ?>
                <input type="hidden" styl="display:none;" name="asl_tax_archive" value="<?php echo $obj->term_id; ?>">
                <?php
            }
        }
    }
    // --- DO NOT CHANGE ANYTHING BELOW HERE EITHER ---
    add_filter( 'asl_query_args', 'asl_archive_page_category_restriction', 10, 1 );
    function asl_archive_page_category_restriction($args) {
        if ( isset($_POST, $_POST['options']) ) {
            parse_str($_POST['options'], $so);
            if ( !empty($so['asl_tax_archive']) ) {
                $term = get_term($so['asl_tax_archive']);
                if ( !is_wp_error($term) ) {
                    $args['post_tax_filter'][] = array(
                        'taxonomy' => $term->taxonomy,
                        'include'  => array($term->term_id),
                        'exclude'  => array(),
                        'logic'    => 'AND',
                        'allow_empty' => false
                    );
                }
            }
        }
        return $args;
    }

    It’s a stretch, but it may actually work.

    Best,
    Ernest M.

    Thread Starter Mushlih Almubarak

    (@mushlih)

    Ok, thank you

    Thread Starter Mushlih Almubarak

    (@mushlih)

    Hi, sorry, that didn’t work
    I’ve put the code in my theme’s PHP functions, but not a single search form appears on the taxonomies page
    I have also changed the category to my category name but it still doesn’t work
    I use this theme

    Plugin Author wpdreams

    (@wpdreams)

    Hi!

    That code is to restrict the searches to the single taxonomy archive page items, it does not put the search there.
    You may have to use the theme editor, or put a search widget there.

    Best,
    Ernest M.

    Thread Starter Mushlih Almubarak

    (@mushlih)

    You may have to use the theme editor, or put a search widget there.

    What search widget should I put? Should it be from your plugin? Or can it be from another plugin?

    Plugin Author wpdreams

    (@wpdreams)

    What search widget should I put? Should it be from your plugin? Or can it be from another plugin?

    Well, if you want to display the search bar from this plugin then the one from this plugin.

    Thread Starter Mushlih Almubarak

    (@mushlih)

    So I just put your plugin shortcode on the category page and it will search for articles only on that taxonomy?

    Plugin Author wpdreams

    (@wpdreams)

    No, you also need the custom code I suggested above. That adds a special parameter to the search form to try to restrict to current archive page only. It is still not guaranteed to work, but it is worth try.

    Best,
    Ernest M.

    Thread Starter Mushlih Almubarak

    (@mushlih)

    Unfortunately, the code still doesn’t work, here’s what I’ve done:

    1. I changed this code:

    add_action('asl_layout_in_form', 'asl_layout_in_form_archive_input', 10);
    function asl_layout_in_form_archive_input() {
        $taxonomies = 'category, post_tag, product_cat'; // Enter the taxonomy names here

    Becomes:

    add_action('asl_layout_in_form', 'asl_layout_in_form_archive_input', 10);
    function asl_layout_in_form_archive_input() {
        $taxonomies = 'akidah'; // Enter the taxonomy names here

    2. I put the code into my child’s theme function.php
    3. I created a template for archive pages using Elementor.
    4. I add a list of articles from a category to the page using the “archive posts” widget from Elementor Pro.
    5. I added a search form using your plugin on the archive page.
    6. I update the page and exit from the page editor, then I test the search form, and I find the search form is still searching for everything on my site, not just articles in that category.
    is there something wrong?
    Thank you

    Plugin Author wpdreams

    (@wpdreams)

    Thanks for the details, it is very hard to tell. Can you please share a link, where I can check this?

    Thread Starter Mushlih Almubarak

    (@mushlih)

    I’m sorry, but it’s a local site.
    Do you want me to provide the JSON file of the elementor template I created? Along with the Elementor pro plugin file?

    Plugin Author wpdreams

    (@wpdreams)

    Thank you, but I’m afraid that is not going to help in this case.

    Best,
    Ernest M.

    Thread Starter Mushlih Almubarak

    (@mushlih)

    It’s weird, I just uploaded the site to the staging site (live) to show it to you, but when I tried the code it worked fine, even though the settings on my staging site and my local site were the same.
    Does the code only work if the site is live?

    Plugin Author wpdreams

    (@wpdreams)

    It should not make any difference whatsoever from the code perspective. Something else may work differently on a live server, which could affect this code, but I honestly have no idea what it could be.

    Thread Starter Mushlih Almubarak

    (@mushlih)

    All right, thank you very much for the help and code
    I will tell you about the code if there is a problem when I have uploaded the local site to hosting
    Thank you

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Some Question’ is closed to new replies.