Logged in user ID as post ID

You can get information on the currently logged in user using the get_currentuserinfo() function. For example: <?php global $current_user; get_currentuserinfo(); $username = $current_user->user_login; $user_id = $current_user->ID; ?> You can then use $username or $user_id in your custom loop. <?php // assign the variable as current category $category = $user_id; // concatenate the query $args=”cat=” . … Read more

Adding option to Gallery shortcode

This code should work in your functions.php add_shortcode(‘gallery’, ‘custom_gallery_function’); function custom_gallery_function($atts) { $user = wp_get_current_user(); // if current user isn’t admin, add posts to be hidden to exclude if(!in_array(‘administrator’, $user->roles)) $atts[‘exclude’] = $atts[‘exclude’] . ‘,’ . $atts[‘hide’]; // call the wordpress shortcode function return gallery_shortcode($atts); }

Date calculations from 2 custom fields

I don’t know how much this will help, but when I’ve done date/time comparisons, I’ve always had to convert them to UNIX timestamps first (converts the date/time to a numeral, which you can compare as less than/greater than/equal to the next number), and then after the difference is sorted, convert it back with date(). A … Read more

How to display posts by current user in a drop down

Use ‘author’ => get_current_user_id() as an argument for get_posts(). This will restrict the found posts to these of the user which is currently logged in. The best reference for the available parameters is still WP_Query::parse_query() in wp-includes/query.php. It is not exactly an atomic function, but you can find parameters not documented elsewhere – like this … Read more

User meta and author meta

class emailer { static function notifyHeart($post_ID) { $interests = get_user_meta(get_current_user_id(), ‘interests’); $to = get_the_author_meta( ‘user_email’, get_current_user_id() ); $post = get_post($post_ID); foreach($interests as $interest) { if(has_tag($interest, $post)) { $email = $to; mail($email, “An article about Heart”, ‘A new post has been published about heart.’); break; } } } } add_action(‘publish_post’, array(’emailer’, ‘notifyHeart’)); Here’s a reworked example. … Read more

Frontend tag edit/submit form

In case that I have understood your (very brief) question and you’re not actually talking about the post_tag-taxonomy then you have wp_insert_term(), which is the underlying API function. Edit As to the comment, there’s the need of meta data for a term and administrator approval. WordPress currently has no native way of adding meta data … Read more

Restore Image Title Text

You can hook into the media_send_to_editor filter and add the title tag to the generated HTML image tag: function wpse_78529_restore_image_title( $html, $id ) { /* retrieve the post object */ $attachment = get_post( $id ); /* if the title attribute is already present, bail early */ if ( strpos( $html, ‘title=” ) ) return $html; … Read more

How can I change a function in a parent theme via a child themes functions.php

On the init action, remove the action calling their function and enqueue an action calling your (differently named) function, like this: add_action(‘init’, ‘wpse_80107_init’); function wpse_80107_init() { // remove parent theme’s header content action remove_action(‘cyberchimps_header_content’, ‘cyberchimps_logo_icons’); // add child theme’s header content action add_action(‘cyberchimps_header_content’, ‘wpse_80107_logo_icons’); } function wpse_80107_logo_icons() { // your custom code here }