• So I have this shortcode:

    [mendeley type=”groups” id=”3913021″ groupby=”year” filter=”keyword=xxx”]

    I need to use this with a search box. So that when someone enters a word into the search box the shortcode is executed with whatever word was entered in place of the “xxx.”

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter ohio_is_for_saraperos

    (@cannabib)

    Is it even possible?

    I’ve tried the _GET form and it just spat errors out at me.

    I assumed I could get user input from the search form and set it as a variable and give the variable in place of “xxx” but that was a swing and miss too.

    I am not going to be able to help you by commenting on whether you could pass user input to the shortcode, because I dont know for sure. Maybe someone else does.

    But what I would like to suggest is

    1) Write your own query using wp_query

    https://codex.www.ads-software.com/Class_Reference/WP_Query

    or if you prefer not to write code, this may be an option:

    2) https://www.ads-software.com/plugins/query-wrangler/

    Thread Starter ohio_is_for_saraperos

    (@cannabib)

    Thanks, but I don’t see how Query Wrangler can help me at all.

    Thread Starter ohio_is_for_saraperos

    (@cannabib)

    <?php
    if (strlen($_GET['input'])>0) {
       echo do_shortcode("[mendeley type="groups" id="3913021" groupby="year" filter="keyword=.$_GET['input']"]")
    } else {echo "Sorry, try again."}
    ?>
    <form action="" method="get">
       <input name="input" value="Keyword Search" />
       <input type="submit" value="Submit" />
    </form>

    That’s what I’ve got so far and the page displays:

    Parse error: syntax error, unexpected T_STRING in /home2/cannabib/public_html/wp-content/plugins/wp-exec-php/wp-exec-php.php(652) : eval()’d code on line 9

    Missing ; at end of echo statements

    Thread Starter ohio_is_for_saraperos

    (@cannabib)

    I feel foolish for leaving those out. I’ve got all the proper marks in place and I still cannot get the job done.

    At last the errors have stopped but I still cannot get the shortcode to execute with the input after it is submitted.

    <code>
    <form action="" method="get">
       <input name="input" value="Keyword Search" />
       <input type="submit" value="Submit" />
    </form>
    
    <?php
    
    $input = $_GET['input'];
    
    if (strlen($input) > 0) {
       echo do_shortcode('[mendeley type="groups" id="3913021" groupby="year" filter="keyword=$input"]');
    }
    ?>
    </code>

    Not sure how to help with that but I looked around and found this – I hope it may help you

    https://www.s2member.com/kb/using-variables-in-a-shortcode/

    Thread Starter ohio_is_for_saraperos

    (@cannabib)

    That was VERY helpful! I was able to solve the problem after viewing the above link.

    Thank you!

    Thread Starter ohio_is_for_saraperos

    (@cannabib)

    For those in the future with the same problem:

    I had to replace the
    "filter="keyword=$input"

    with

    "keyword="<?php echo $input; ?>""

    <code>
    <form action="" method="post">
       <input name="input" value="" />
       <input type="submit" value="Keyword Search" />
    </form>
    
    <?php
    
    $input = $_POST["input"];
    $input = strtolower($input);
    
    if (strlen($input) > 0) {
       echo do_shortcode('[mendeley type="groups" id="3913021" groupby="year" filter="keyword="<?php echo $input; ?>""]');
    }
    ?>
    </code>

    Glad that you got it working ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Need help passing user input to shortcode’ is closed to new replies.