• Resolved jasghar

    (@jasghar)


    hey, thanks for the plugin. i used the shortocde to show the search terms on frontend. i just want to know how can I also add link to those search terms like if there is a search term of “best cars 2022” then it should have a link inside it so when users click on it it should automatically search this term for them. but for now there’s simple li elements are shown

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Cornel Raiu

    (@cornelraiu-1)

    Hi @jasghar ,

    The shortcode has an output filter that can be used to customise the output. The easiest way to do it is to add the code in this gist I just put together in the functions.php file of your child theme:

    https://gist.github.com/cornelRaiu/f0ef6f8299441dcdcf3eed34f6c20367

    Let me know if that helps.

    Thanks!

    • This reply was modified 2 years, 7 months ago by Cornel Raiu.
    Thread Starter jasghar

    (@jasghar)

    @cornelraiu-1 thanks for your response i did checked it and its working awesome. thanks again. but I do have 1 more thing to ask when I search for the first time the results are shown on somekind of this URL
    domain.com/?s=search-term

    and when I come back and click on my last search term it shows this URL
    domain.com/search/search-term

    why that? can I change it?

    Plugin Author Cornel Raiu

    (@cornelraiu-1)

    @jasghar that happens because friendly URLs are active on your website so WordPress uses the registered search permastruct to build the URL.

    To go around this you can define this function in the functions.php:

    if ( ! function_exists( 'get_search_link_no_permastruct' ) ) {
    	function get_search_link_no_permastruct( $search_term ) {
    		return home_url( '?s=' . urlencode( stripslashes( $search_term ) ) );
    	}    
    }

    and then, in the code in my gist, replace all the occurrences of:

    get_search_link( esc_attr( $term['term'] ) )

    with

    get_search_link_no_permastruct( esc_attr( $term['term'] ) );

    The result should be exactly the one you are looking for.

    Plugin Author Cornel Raiu

    (@cornelraiu-1)

    @jasghar can you give me an update on this? Does my solution work as you need it to?

    Thanks!

    Thread Starter jasghar

    (@jasghar)

    thanks for your reply and the plugin and sorry for my late reply.
    I used this shortcode to show search terms on frontend
    [mwtsa_display_search_stats unit=”month” most_searched_count=”10″ most_searched_only_with_results=”false”]

    but I dont know why it seems to be having a problem with displaying terms the right way.
    Right now it shows the search terms in like alphabetical order maybe
    like if i entered Apple first, banana second, citrus third, this will be in flow
    but if i enter another terms starting with B say Baby it will show on fourth or after banana search term rather than showing at the first place.
    becuase I want to show keywords in order they are searched.
    if apple is searched first, banana second, citrus third then if i search baby again the baby should appear at the first place rather then showing at last place or in any random order.

    and thats the reason maybe some of the search terms dont show in top 10 keyword displayed on frontend. can you help with this?
    thanks

    Plugin Author Cornel Raiu

    (@cornelraiu-1)

    @jasghar the delay in showing the results must be caused by WordPress caching the widget output.

    based on the options you are applying to the shortcode, the results will be sorted by the number of searches in the past month.

    So, for example, when someone searches:

    Asparagus
    Banana
    Citrus
    Apple

    They will show, most probably in the following order:

    Apple
    Asparagus
    Banana
    Citrus

    But, if someone else searches for Citrus again, Citrus will be shown first.

    Citrus
    Apple
    Asparagus
    Banana

    The sort order is: number of searches DESC, alphabetical ASC.

    Also, keep in mind that this is a global widget and not a user/browsing session related one.

    I am planning a plugin update release later today and, initially, I did not want to touch the shortcode with this update. But, seeing that you need it, I will add a filter to the shortcode search results and, that way, I will be able to give you another gist with how you can achieve what you need here.

    Please answer the following questions:
    1. Do you want to display searches by user or global?
    2. If the answer to q1 is “user”, are your users logging in? The search by user only works for logged in users at this moment.

    Thread Starter jasghar

    (@jasghar)

    thanks for your response. it cleared some of my confusion.
    what do you mean by global? if you mean searches of each user on site then yeah this is something i want.
    say theres two users on site so if user one searches
    apple

    then this search term will be displayed to others two as well
    when the user two search
    banana

    this term will be appeared before apple now
    banana
    apple
    like this
    and each three users will be able to see this

    and now if user three searches citrus then the order be
    citrus
    banana
    apple

    means each new search be prepend to the current searches.
    no sort by alphabetical order or anything.

    i want to show in order they are searched.

    is this something posssible to do? or will be possible by the update you will do today?

    thanks for your efforst, quick replying and this awesome plugin

    Plugin Author Cornel Raiu

    (@cornelraiu-1)

    @jasghar yes. That will definitely be easy to do with the update I am preparing as we speak.

    I am glad you like the plugin.

    Will get back to you with the code needed to achieve this in a gist. We’ll also make some changes to the code that I did in the earlier gists when I added links to the search terms because we’ll have a cleaner way to do that now.

    Thread Starter jasghar

    (@jasghar)

    thanks @cornelraiu-1 for everything. I’m glad to choose this plugin for my site. its really usefull, easy to use and with your fast support it scores 100 out of 100

    Thread Starter jasghar

    (@jasghar)

    @cornelraiu-1 ‘I got plugin update in my website. did you updated it?

    Plugin Author Cornel Raiu

    (@cornelraiu-1)

    @jasghar I updated it. There is another change I have to do in the plugin and will push another update in a bit in order to be able to take care of your request without rewriting the whole query logic.

    I will get back to you in a bit.

    Plugin Author Cornel Raiu

    (@cornelraiu-1)

    Hi @jasghar ,

    Please make sure you update the plugin to V1.4.2 and then you will be able to use a new, undocumented ( yet ) shortcode.

    That is:

    mwtsa_display_latest_searches

    For your setup, the shortcode will need to be:

    [mwtsa_display_latest_searches unit="month" count="10" only_with_results="false"]

    This should always show the latest searches.

    And then, in your functions.php add the code in this gist:

    https://gist.github.com/cornelRaiu/16c0008274586c407921fa919759103d

    Let me know.

    Thanks!

    Thread Starter jasghar

    (@jasghar)

    sorry for late reply let me try this right now and i get back to you. hope it dont affect my css

    Thread Starter jasghar

    (@jasghar)

    okay tried it and yep it overrides my current styling plus showing in the searched order as wanted the things i noticed is if i search a term
    apple
    3 times it will show apple three times in a row instead of showing once I wonder if we can sort out this too?. and thanks for the update dear.

    Thread Starter jasghar

    (@jasghar)

    okay the styling was overwritten because of the container element’s class change. but I fixed the styling. thanks for everything

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘how to direct users on the specified search term’ is closed to new replies.