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

Showing a different gallery in a seperate post

You can try this function instead of your multi_gallery_shortcode(): function multi_gallery_shortcode($atts, $content=null) { extract( shortcode_atts( array( ‘pid’ => 0, ), $atts ) ); //format the input $pid = intval($pid); // construct a post object dependent on the input value if($pid>0){ // query a post object $pobj = get_post( $pid ); }else{ global $post; // current … Read more

Plugin Handle URL With Custom Theme

Here’s a slimmed-down version of what I usually do. Replace wpse100645 with whatever you want, but be respectful of the fact that you don’t want to interfere with a site’s content. <?php /** * Create a custom path and process code when it gets triggered * * @author Matthew Boynes */ if ( !class_exists( ‘WPSE_100645_Custom_Page’ … Read more

Secure Pages Best Practice

Not sure about the best practices, but I have a few custom login-sensitive pages which simply display a message if user is not logged and is trying to view the page directly: $logged_in = is_user_logged_in(); if($logged_in) { ?> <article id=”post”> <?php the_content(); ?> </article> <?php } else { _e(‘You are not logged in. Please ‘, … Read more

Auto gallery from folder contents

It sounds like you just need shortcode to gather the contents of a folder and display a grid of those items. The shortcode is pretty easy to setup. $gallery = do_shortcode(‘[folder_gallery title=”XYZ” folder=”wp-content/uploads/2015/11″]’ ); echo $gallery; Then you just need to glob a directory and render your gallery from the files. I didn’t include a … Read more

How do I write this shortcode? [closed]

function webhosting_products_shortcode( $atts, $content = null) { ob_start(); include(‘shortcodecontent.php’); $shortcode = ob_get_clean(); return $shortcode; } add_shortcode(‘webhosting’, ‘webhosting_products_shortcode’); Improvements include: Your html is now in a separate file, and can be written as is, rather than as a long PHP string Trailing whitespace is bad, untidy, and should be highlighted by your code editor to point … Read more