do_shortcode() within Admin Page

Instead of calling do_shortcode() just call the function associated with the shortcode. Example There is a shortcode named [example] and a function registered as shortcode handler: function example_shortcode( $atts = array(), $content=”” ) { extract( shortcode_atts( array ( ‘before’ => ”, ‘after’ => ”, ), $atts ) ); return $before . $content . $after; } … Read more

How can I create a shortcode to show the number of posts of actual day?

I tried some codes, and I think finally works after several tries: function ts_day_f() { $posts= get_posts(array( ‘numberposts’ => -1, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘date_query’ => array( ‘column’ => ‘post_date’, ‘after’ => ‘today’, ‘before’ => ‘tomorrow – 1 second’, ) )); if ( is_user_logged_in()) { //return count($posts); $c = count($posts); … Read more

list of custom post by custom field in frontend

The main issue is that you’ve mixed up two methods of querying posts. You’re querying the correct posts here: $posts = get_posts(array( ‘numberposts’ => -1, ‘post_type’ => ‘assessment’, ‘meta_key’ => ‘customer’, ‘meta_value’ => $current_user_id )); But then the posts you’re actually looping through are queried here: $the_query = new WP_Query( $args ); Where $args is … Read more

Trying to create a shortcode to display categories with a specific product tag

You need to pass your attributes in the shortcode as key-value pairs, and use them in php as an array as follows: [tagtagtag tag_id=246] function get_categories_with_product_in_tag( $atts ) { global $wpdb; return $wpdb->get_results( $wpdb->prepare( “SELECT categories.* FROM “. “{$wpdb->prefix}terms categories “. “INNER JOIN {$wpdb->prefix}term_taxonomy ctax ON (categories.term_id = ctax.term_id) “. “INNER JOIN {$wpdb->prefix}term_relationships crel ON … Read more

pass complex json as shortcode parameter

Maybe there is a better solution, but serialize seems to do the job. Instead of json I could pass json_decoded and then serialized parameters. For example $jsonval = json_decode(‘{“foo”: “bar”}’); $serialized = serialize($jsonval); Shortcode will be something like: [myshortcode parameters=”O:8:”stdClass”:1:{s:8:”foo”;s:3:”bar”;}”] At this point I can handle parameters unserializing them: function myshortcodehandler($atts){ $arrparameters = (array) unserialize($atts[“parameters”]); … Read more

How to search order using database frontend short code WordPress

Use the below code it may help you and sure that your sql query is correct then it will be work properly. function wpb_demo_shortcode() { global $wpdb; $results = $wpdb->get_results( $wpdb->prepare(“SELECT DISTINCT o.order_id, o.`order_item_name`, om.`meta_value` as ‘bcs’, (select pm.`meta_value` from `wp_postmeta` as pm WHERE o.order_item_id = om.order_item_id AND pm.`post_id` = o.order_id AND pm.`meta_key` = ‘2-certificate’) … Read more

Passing function arguments via a shortcode

You can absolutely pass arguments to your shortcode, but not in the method you described. Please see the Shortcode API (https://codex.wordpress.org/Shortcode_API) Your shortcode with arguments will look more like: [vertical_posts label=Answers category=answers number=4]