Get User ID from within a plugin

If you want current user id only then use get_current_user_id. because it reduce execution time. get_current_user_id get only current user id where wp_get_current_user get all user data. Else every things is perfect. $user_id = get_current_user_id(); $loc_statuss = $wpdb->get_row( “SELECT status FROM profile_location INNER JOIN relation_user ON profile_location.loc_id=relation_user.loc_id WHERE relation_user.user_id=”.$user_id ); $loc_status = $loc_statuss->status;

how to display all posts Custom fields dynamically?

<div class=”col-xs-12 col-sm-12 col-md-8 col-lg-8 left_column”> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1> <?php the_title();?> </h1> <?php $post_meta = get_post_meta(get_the_ID()); foreach($post_meta as $key=>$value) { echo “<strong>”.$key.”</strong>”.” => “; foreach($value as $nameAr=>$valueAr) { echo “<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”; echo $nameAr.” => “.$valueAr; } echo “<br >”; } the_content(); endwhile; endif; ?> </div>

How to extract images of post and pages excluding header and logo image in wordpress?

I believe this will get you all of your attachments: $q = new WP_Query( array( ‘post_type’=>’attachment’, ‘post_status’=>’inherit’ ) ); var_dump($q); You could further restrict that by adding other parameters, for example, ‘post_mime_type’ => ‘image’ would restrict only to images. That will return all images though, not just the ones attached to posts. What you want … Read more

Dynamic homepage according to user role

To use a different page’s content on the homepage based on a logged-in user’s role you can do this: In your functions.php file add this code: function wpse_273872_pre_get_posts( $query ) { if ( $query->is_main_query() && is_user_logged_in() ) { //work-around for using is_front_page() in pre_get_posts //known bug in WP tracked by https://core.trac.wordpress.org/ticket/21790 $front_page_id = get_option(‘page_on_front’); $current_page_id … Read more

An old plugin self-made stoped sending mail

Many E-Mail-Hosters changed their rules to prevent spam. Often times, E-Mails that have one domain name in their “from”-Tag and come from a server with a different domain are rejected. So my guess is, maybe the emails are still sent, but not received. You can check this by changing this line: $headers=”From: “.$senderEmail.’ <‘.$senderName.’>’ . … Read more

WP get_permalink Return Wrong URL

IMO It is rarely a good idea to evaluate shortcodes outside of the specific post page as too many times you need the context for either the evaluation itself or styling. Your problem is most likely related to the use of the_post and wp_reset_postdata. What is exactly the post being reset to in that case? … Read more

Help!! I Screwed up my WP

since i posted as a comment and most people miss the good tips that are in the comments, I’m posting again as an answer The reason is because GD Star rating plugin creates custom capabilities and your query deleted all references of %rating% it deleted the wp_user_roles option which holds all capabilities roles. the solution … Read more

I can’t access wordpress functions from an ajax php call

You are making a new request to the server and you appear to be loading a page that is not loading WordPress core functions. I’d need to see your HitCount.php to confirm this but I can’t think of another explanation. Loading WordPRess files piecemeal is tricky and prone to breakage as core code changes. You … Read more

Author Specific URL’s in WordPress

here you go: add_action(‘init’, ‘wp_new_flush_rewrite_rules’); //Run this action only ONCE if not you are looking at 2 extra db queries on every page load so dont forget to comment it out function wp_new_flush_rewrite_rules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } add_action(‘generate_rewrite_rules’, ‘new_rewrite_rules’); function new_rewrite_rules( $wp_rewrite ) { $post_type=”post”; $new_rules = array( ‘writer/(.+?)/page/?([0-9]{1,})/?$’ => ‘index.php?post_type=”.$post_type.”&meta_key=writer&meta_value=”.$wp_rewrite->preg_index(1).”&paged=’.$wp_rewrite->preg_index(2), ‘writer/(.+?)/?$’ => ‘index.php?post_type=”.$post_type.”&meta_key=writer&meta_value=”.$wp_rewrite->preg_index(1), … Read more