$wpdb->get_var not returning a result
$wpdb->get_var returns a single variable, but your SQL statement has SELECT * which returns a row of multiple columns. You need to change your SQL statement to SELECT ID … instead of SELECT * …
$wpdb->get_var returns a single variable, but your SQL statement has SELECT * which returns a row of multiple columns. You need to change your SQL statement to SELECT ID … instead of SELECT * …
Working code for adding widget to wp dashboard with information from custom DB: /** * Add application widget to the dashboard. */ function addApplicationWidget() { wp_add_dashboard_widget( ‘submitted_applications’, ‘Submitted Applications’, ‘showApplicants’ ); } add_action( ‘wp_dashboard_setup’, ‘addApplicationWidget’ ); function showApplicants() { global $wpdb; $appTable = $wpdb->prefix . “applications”; $query = $wpdb->prepare(“SELECT * FROM $appTable WHERE %d >= … Read more
I figured this problem out literally seconds before I posted the question, so I thought I would go ahead and post the answer here. I’ve noticed there is not a lot of consolidated help for this problem out there. This will help you if your “Older Posts” or “Newer Posts” links give you a 404 … Read more
See if this doesn’t do it: First, the callback for that Ajax search (the wp_link_query method in wp-includes/class-wp-editor.php) suppresses the normal filters. We have to turn them back on for this particular query. function undo_suppress($qry) { global $_POST; if (isset($_POST[‘action’]) && ‘wp-link-ajax’ == $_POST[‘action’]) { $qry->set(‘suppress_filters’,false); } } add_action(‘pre_get_posts’,’undo_suppress’); Now we can use the posts_where … Read more
To show a list by Year DESC and by month ASC: change your post type with custom_post. global $wpdb; $posts = $wpdb->posts; $sql = “SELECT DISTINCT(YEAR(`post_date`)) as years FROM $posts WHERE post_type=”custom_post” ORDER BY years DESC”; //Get all post year list by DESC $result = $wpdb->get_results($sql); foreach($result as $rs) { echo ‘<h2>’.$rs->years.'</h2>’; $args = array( … Read more
use the indentical comparison operator: if(get_query_var(‘cls’) !== ” && get_query_var(‘ch’) !== ”) { mcs_textbook_chapter($dialect, $cls, $ch); } elseif(get_query_var(‘cls’) !== ”) { mcs_textbook_chapter($dialect, $cls); } else { mcs_textbook($dialect); }
There seemed to be two easy-to-solve problems: The function was being declared twice without checking if it already existed. After solving that issue, i needed to post a “post” post to refresh the feed, but after that custom post types appeared in the feed without further refreshing nor publishing standard posts.
Finally found out using two (single) posts metas : likes_log where I keep up to date an array where each entry is the time the item was liked. Entries are removed if they are too old (here, >1 month) likes_log_count where I update the number of entries in the previous log. function update_likes_monthly_count(){ if ( … Read more
Whilst WordPress has gotten pretty good at db caching for loops (thumbnails, post meta, terms), it does not pre-emptively cache users (authors). So if you have 5 different authors across all the posts in your loop, that’s 10 queries (1 for the user object, 1 for the user’s meta cache stash). It’s thanks to WP_Query::setup_postdata() … Read more
get_query_var(‘paged’) giving same result