Adding ads code between comments

The end-callback of wp_list_comments() One way is to use the end-callback argument in: wp_list_comments( [ ‘end-callback’ => ‘wpse_comments_ads_injection’, … other arguments … ], $comments ); in addtion to your other wp_list_comments arguments, by defining: function wpse_comments_ads_injection( $comment, $args, $depth ) { static $instance = 0; $tag = ( ‘div’ == $args[‘style’] ) ? ‘div’ : … Read more

Check if row exists before inserting

There are several problems with your function. For example, $tablename points to a table that does not exist. And you don’t need it anyway. If you are trying to create a new user if that email does not exist then try this: function register_user() { global $wpdb; $name = $_POST[‘name’]; $email = $_POST[’email’]; $password = … Read more

Change the slug of a particular page every x hours

You’ll need a two step process for that. Create a function that actually changes the slug (not rewrite it) Schedule an event in WordPress to run that function in every X hours. Here are something to start with function wpse402903_schedule_event() { add_action( ‘wpse402903_cron’, ‘wpse402903_cron_callback’ ); if ( !wp_next_scheduled(‘wpse402903_cron’) ) { //Change 12 to your interval … Read more

greatest() function returns undefined property

I think you want to use get_var(), not get_row() – looking at the documentation, MySQL’s GREATEST just returns a single value. $results will then just be the value of the greatest (be it up or down). If you want the greatest up and the greatest down, use; $wpdb->get_row(“SELECT GREATEST(up) AS ‘up’, GREATEST(down) AS ‘down’ …”)

How would I create a shortcode to display a custom post within a page or regular post?

There are great tutorials about shortcodes all over the web and some good examples here but just to get you started: add_shortcode(‘film_q’, ‘film_shortcode_query’); function film_shortcode_query($atts, $content){ extract(shortcode_atts(array( // a few default values ‘posts_per_page’ => ‘1’, ‘post_type’ => ‘film’, ‘caller_get_posts’ => 1) , $atts)); global $post; $posts = new WP_Query($atts); $output=””; if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); … Read more

How to determine which custom header image is being shown

For the TwentyEleven theme, you can place this above your BODY tag in header.php. The theme will recognize that $header_image is already set, so no other mods would be necessary. $header_image = get_header_image(); $image = basename($header_image); $image = explode(‘.’,$image); $class=”header-image-“.$image[0]; Add the $class parameter to the body_class function to insert your header image class. body_class($class);

modify a function filter

The filter exists to avoid the need for replacements in the plugin code. What you probably need is: add_filter( ‘wpsc_purchase_logs_cap’, ‘wpse_72095_admin_to_editor’ ); function wpse_72095_admin_to_editor() { return ‘edit_others_posts’; } This will change the capability/role to editor.