• Resolved mandejp

    (@mandejp)


    I’m trying to use MyCred to allow users to earn points by clicking search in the search bar from my website. I need to embed the code in the search bar, but when I do that it doesn’t show up.

    My syntax:

    <form role="search" method="get" class="example" action="https://google.com/search" method="GET" style="margin: auto; max-width: 650px;">
    <input type="text" placeholder="<?php esc_attr_e('Search...', 'google'); ?>" value="" name="q" id="s<?php echo esc_html(rand (0.999999)); ?>" type="search" >
    </form>

    Please support.

    • This topic was modified 2 years, 9 months ago by mandejp.
    • This topic was modified 2 years, 9 months ago by Jan Dembowski.
Viewing 15 replies - 1 through 15 (of 15 total)
  • A.Tariq

    (@arsalantariq)

    @mandejp,

    Thank you for contacting us, please share the screenshot of your frontend and backend. It will help us in identifying the issue.

    Thread Starter mandejp

    (@mandejp)

    Thanks for contacting.
    I create a search bar on the homepage menu using the code above.
    This is the search box on the menu. https://imgur.com/42c2HVr
    I want when member search any on that frame there will be points.

    A.Tariq

    (@arsalantariq)

    @mandejp,

    You can use add_creds() function to reward users points on different events. For reference, you can check this doc link https://codex.mycred.me/chapter-v/playing-with-balances/

    • This reply was modified 2 years, 9 months ago by A.Tariq.
    Thread Starter mandejp

    (@mandejp)

    I added by this way but not working.

    <form role="search" class="search search-form" mycred_link href="https://google.com/" action="https://google.com/" method="GET">
    	<label>
    		<span class="screen-reader-text"><?php esc_html_e( 'Search for', 'oke' ) . ':'; ?></span>

    I also tried with this, but also not able to automatically add points to the user every time they search in the search bar

    <form role="search" class="search search-form" action="https://google.com/" method="GET" mycred_add( 'reference', $user_id, 1, 'Points for search!' );>
    	<label>
    		<span class="screen-reader-text"><?php esc_html_e( 'Search for', 'oke' ) . ':'; ?></span>
    A.Tariq

    (@arsalantariq)

    @mandejp,

    The function where you are adding this code you can use some add_action to reward user points using add_creds() function.

    Thread Starter mandejp

    (@mandejp)

    Can you send me the code that I can apply? Thank you.

    A.Tariq

    (@arsalantariq)

    @mandejp,

    Use any action hook where the user is searching.

    add_action('your_action', 'your_action_func');
    
    function your_action_func() {
    
    $mycred->add_creds(
        'reference',
        $user_id,
        5,
        'Points for clicking search in the search bar'
    );
    }
    Thread Starter mandejp

    (@mandejp)

    Thanks, I’ll try it out and get back to you.

    A.Tariq

    (@arsalantariq)

    @mandejp,

    Sure, Please do let us know if you need any assistance.

    Thread Starter mandejp

    (@mandejp)

    I installed and got the score (I use mycred_link). But when the user clicks on that link, the point is calculated continuously.
    So how do I set a limit to earn points per day when the user clicks on mycred_link?
    And how to set the time interval for each different click (for example, the user clicks on mycred_link, and 5 seconds later they click on mycred_link to calculate the next point, even if in about 5 seconds before they click on mycred_link, it will also be counted. no points)?

    A.Tariq

    (@arsalantariq)

    @mandejp,

    You can wrap the add_creds function under the below condition. One user will get points only once for clicking on a particular link. This is how myCred link click hook works. A user cannot get points multiple times for clicking on the same link.

    if ( ! $this->over_hook_limit( '', 'reference', $user_id ) ) {
    
    $mycred->add_creds(
        'reference',
        $user_id,
        5,
        'Points for clicking search in the search bar'
    );
    }
    
    • This reply was modified 2 years, 9 months ago by A.Tariq.
    Thread Starter mandejp

    (@mandejp)

    Can you guide me to limit points in mycred link like Viewing Content (Points per day, week, month)?

    A.Tariq

    (@arsalantariq)

    @mandejp,

    You can have a look at the code of our other myCred hooks for reference. Since you have done some custom work you will have to do some coding to make it work.

    Thread Starter mandejp

    (@mandejp)

    I have tried installing and trying ways but no success. I guess I have to skip adding points to users when they search

    A.Tariq

    (@arsalantariq)

    @mandejp,

    Have you made any custom hook to achieve your requirement?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Embedding MyCred link in search’ is closed to new replies.