Your ShortCode callback method should take an atts parameter that stores the attributes passed to it from the do_shortcode call which is I am assuming how you are getting the $q parameter for the database query.
The callback method should also return instead of echo the output.
Without seeing any of the output/error messages I would say you’ll need to create a different method for the shortcode. Perhaps one that outputs the search form that will trigger the ajax calls.
Take a look a the Shorcode API for details on creating the callback.
Related Posts:
- do_shortcode inside AJAX callback
- Custom Shortcode AJAX 400 Bad Request
- How can I run shortcode after click with ajax
- Ajax not returning anything on form submit
- How to use shortcodes on a widget sidebar when doing an ajax call?
- Shortcodes not working in an AJAX call
- How to get gallery id inserted to a post?
- Different uniqid when calld in wp_localize_script and shortcode
- How to add AJAX in a custom PHP function using Google sheets API
- AJAX and Shortcode with Parameters
- wp_editor in thickbox
- do_shortcode via ajax
- Pass data back to TinyMCE from Thickbox
- Getting error on submitting form using Ajax with shortcode
- Regenerating WordPress shortcodes based on value with AJAX
- Use Contact Form 7 with Ajax
- AJAX and do_shortcode
- Remove a short code and update it’s content (AJAX)
- Cannot modify class property from shortcode handler function
- Use Shortcode on Custom Page
- Do embed shortcode on wordpress ajax request
- Ajax callback and shortcode functionality
- Load next post by ID on a single page
- Access Shortcode in ajax code?
- load plugin with ajax [duplicate]
- How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?
- Working with Shortcode, AJAX, Elementor
- Using wp_editor in shortcode
- Why are you using add_action for shortcode?
- How to get URL param to shortcode?
- How to display the names of users from a specific group with a shortcode?
- shortcode for logo image
- Stop strip_shortcodes() stripping content inside shortcodes
- Using audio shortcode for .mp3 URLs with a query string
- Get multiple shortcode attribute values
- How do i link gallery thumbnails to different url’s using the wp native gallery?
- How to display some selected user meta data on a specific page with a shortcode?
- Gallery shortcode menu order fix no longer working on WordPress 4.0
- How to save a shortcode in a Gutenberg custom block?
- Shortcode displays only default attribute values
- Can a shortcode function this way
- Dynamically create shortcodes using add_shortcode and a callback
- Passing attributes to shortcode dynamically
- Stop parsing shortcodes
- Meta tags in shortcode
- Gist shortcode is not working
- Display post metadata: “title, category, author, date” with shortcode
- shortcode javascript not working on custom template file inside theme folder
- Check if post has gallery images/media
- Stop auto formatting in shortcodes
- Get URL Param Plugin and Inserting Result in Widget Code
- Problem with using custom shortcode with ACF WYSIWYG field
- Add shortcode support to custom field
- Preserve shortcode content formatting
- Shortcode help: If no image entered take default
- Reloading a Mediaelement audio player
- Shortcode is not processed when added to option field using wp_editor
- Adding Shortcode Values to wp_head
- Shortcodes: closing shortcode not being processed
- Retrieving post excerpt as a shortcode
- Insert PHP code via shortcode?
- Trying to call dynamic content as a shortcode attribute
- What is the correct syntax to append a URL using a shortcode for an iframe?
- Shortcodes in RSS excerpts
- enqueue script with get_shortcode_regex
- How to set a variable in a shortcode and reference it in another shortcode in the same post?
- How to get_post_meta in a shortcode in excerpt on archive pages
- WordPress upgrade adding additional quote marks to shortcode output
- How to build a shortcode for tabs
- Creating tabs shortcode
- SImple Example To Update User Info From Front End [duplicate]
- using shortcodes in theme content
- How to: Simple Nested Shortcode [closed]
- get_posts not working on homepage?
- ACF repeater + group shortcode
- Custom shortcode skips every 2nd shortcode
- Wrap template code with shortcodes
- Gutenberg Shortcode Chooser Block
- How to cache a custom API call?
- Shortcode custom query not passing value
- How to create custom variables in wordpress
- Unknow shortcode read on display site
- Onclick want to call shortcode in wordpress
- Working with Contact Form 7 pipes
- How to disable cache for the content returned by a shortcode
- Hide shortcodes content from the excerpt?
- Can we create a shorcode to move next page?
- launch a shortcode from a link
- how to add acf value to other plugins shortcode?
- Only execute specific shortcodes
- About redundant code when I use shortcode to output the HTML from a variable
- how to show last 5 images from the one post gallery
- Add JavaScript in footer if shortcode used in page [duplicate]
- Is there a way I can return terms by name using a shortcode?
- How i make a shortcode from this code
- Shortcode Attributes – post__not_in array
- Shortcode with foreach
- How do write this type shortcode? [closed]
- How to reuse php templates as shortcodes?
- Shortcode attributes from meta query variables