Adding variable in WordPress shortcode

Rather than passing the variable contents in to the shortcode, you would probably be better to pass in the URL parameter you are setting, i.e. [post color=”color” width=”980″ heigh=”610″]. Because your shortcode will execute during load in PHP, you can then tell your shortcode function to store the value of $_GET[‘color’] to later use in … Read more

shortcodes, custom php and their errors

The answer is: function reservations_yesterday() { global $wpdb; $results = $wpdb->get_var (“SELECT SUM(`mattiscool`), booking_date FROM `wp_cbxrbooking_log_manager` WHERE `booking_date` = CURDATE() -1”); return $results; } add_shortcode(‘name’, ‘reservations_yesterday’);

wpdb->query returns different value to phpMyAdmin

You need to read the manual for the functions you’re using as all the information for how to debug is contained there. $wpdb-query() description is very clear. The return value is: (int|bool) Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error. As mentioned … Read more

Conditional formatting on data fetched from MYSQL

First a few notes: Shortcodes do accept arguments, so you could write [marks subject=”Biology”] (@see https://codex.wordpress.org/Shortcode_API) You should never ever pass raw data directly into a SQL statement, WordPress uses PDO, this means you can prepare statements. (@see https://developer.wordpress.org/reference/classes/wpdb/prepare/) Using the get_results will return an Array, object or null (@see https://developer.wordpress.org/reference/classes/wpdb/get_results/). There are many approaches … Read more

Function is printing twice – any suggestions?

After realizing that I was trying to use the same shortcode for two different types of lists, it was easier to just separate them in two different shortcodes. To list all posts and break them up by type: /** * Shortcode for listing all tools matching tags * Usage: [useful-tools-all desc=”true” li=”true” tags=”health, teens”] * … Read more