Elementor Archive Posts Nothing Found Message Override

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Elementor Archive Posts Nothing Found Message Override

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28383
    rsmithgs25
    rsmithgs25
    Participant

    Hello,

    I just purchased your plugin and am enjoying it so far, but am looking for some assistance because there is a problem with the No results text being overwritten by the Elementor Pro Archive Posts block’s Nothing Found message.

    Image of my Page with the Search bar with nothing found
    Image of Elementor’s Nothing Found Message
    Image of Ajax Search Pro No results text

    Ultimately, it would be better if I could return my post called “Unlisted Professor” if we return no results from the user’s search, but if that is not possible, I’d settle for the Ajax Search Pro No Results Text message and link appearing as well.
    I think it’s possible to return whatever after a query, but I just don’t know where to put the code so it is related only to this search form. I’m specifically looking at these two StackExchange/StackOverflow posts:
    Force WP Query to return No Results
    I’d use this to just say "post__in" => array(post_id) following WP_Query Documentation
    and
    Is WP_Query Empty
    Essentially put the post__in => array(post_id) within the else statement.

    Is this possible? Thanks for your help!

    #28389
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you for the details!

    I tried to log-in to check the issue, but the details does not work, either the username or password are invalid.

    I’m afraid this is not possible unfortunately. The message comes from the elementor core itself. The regular posts or product widget does not have a no-results message, so the plugin uses a hook to override that, but for the archive widget it won’t work.
    I’m not sure if there is a simple way to display a custom post there either, as that works differently from the WordPress WP_Query, it uses a separate class and different hooks for that. There is this documentation, but ti does not work with the posts archive as far as I know, only the posts widget.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #28422
    rsmithgs25
    rsmithgs25
    Participant

    Thank you Ernest! I think you got me on the right track. I’ll look more into that documentation for the Posts block. I just assumed because I was on an Archive page I needed to use the Archive Posts block.

    I’ll let you know if I can get it to work or if I have any further questions regarding your plugin.

    #28432
    rsmithgs25
    rsmithgs25
    Participant
    You cannot access this content.
    #28434
    rsmithgs25
    rsmithgs25
    Participant

    I was successful in being able to get the correct No Results message now that I’ve switched over to the Posts block.

    Using the Elementor Custom Query Filter documentation as a guide, below is what I’ve tested. I’ve been able to return a specific post on the initial query (when the page initially loads), but I’m wanting to return the specific post if they type in the search a term that returns no results.

    /*Attempt return specific post if no posts found in query*/
    add_action('elementor/query/fellow-donations', function($query){
            if(!$query->have_posts()){
                $query->set('post__in', array(810)); //ends up returning the 1 post even if there are posts.
                //only returns this for the initial page load, after someone attempts to search and then backspaces everything shows
            }
        
    });

    I’m wondering if it may not be working due to another issue as well. When the page initially loads (without this script) my post 810, which is named “Unlisted Professor” is there, but if someone searches and then back spaces to have nothing in the search bar again when all of the elements load back in the “Unlisted Professor” post is no longer listed. I am not excluding it within the Advanced Options.

    Thanks again for your help!

    #28443
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I think the problem here is, that checking $query->have_posts() returns false always, because the query did not execute yet. Basically the $query->have_posts() function is used to check if there are any matches, but after the query is finished. But then again, calling $query->set(..) has no effect.
    I’m not sure if that hook allows you to check the query results, because it is triggered before the query is executed.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.