How to assign results to variables?

Best luck while you learn. $fivesdrafts = $wpdb->get_results( ” SELECT ID, post_title FROM $wpdb->posts WHERE post_status=”draft” AND post_author = 5 ” ); foreach ( $fivesdrafts as $fivesdraft ) { echo $fivesdraft->post_title; } This example has been sponsored by WordPress codex. In your case $wpdb->get_results( Should become like: $variable_to_print = $wpdb->get_results(

Change the second role depending on the first

Because you are operating on the current (logged in) user – you need to accept parameters in your callback so that you can operate on the user whose role is being set: rb_update_user_role( $user_id, $role ) { // error_log( “Setting user $user_id to role $role” ); if ( $role !== ‘s2member_level0’ && $role !== ‘s2member_level1’ … Read more

wordpress function through ajax not being called

Based on your comments, I don’t think the MyAjax variable is being localized using wp_localize_script(). In your case, you’ll most likely need something like the following: wp_localize_script( ‘script’, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ) ); That said, I don’t really have enough information to provide a more detailed answer. EDIT: This and the … Read more

different body classes for each category

If i understood what you are lookin for, this should work, it uses get_queried_object() function: // Adding categories name to body class on archives add_filter(‘body_class’,’add_category_to_body_class’); function add_category_to_body_class( $classes ) { // check if in category if ( is_category() ) { // get the queried object, in this case, a category object, and assigns to a … Read more

How to use if (is_page_template (”))

is_page_template() checks against post type templates specified by the theme using /** * Template Name: My Template */ at the top of the template file. Not any arbitrary template file. For this, you might wanna check out the answers over at Get name of the current template file. You could grab the code from the … Read more

Pagination not working on my archive page for a custom post type

So I got this to work by adding this function to functions.php // Custom query for events function set_posts_per_page_for_events_cpt( $query ) { if ( !is_admin() && $query->is_main_query() && is_post_type_archive( ‘events’ ) ) { // set date $currentdate = date(“Y-m-d”,mktime(0,0,0,date(“m”),date(“d”),date(“Y”))); $meta_query = array( array( ‘key’=>’event_date’, ‘compare’ => ‘>=’, ‘value’=> $currentdate, ‘type’ => ‘DATE’, ), ); $query->set(‘meta_query’, … Read more