Display the 3 latest WordPress Posts on a Static Page Outside WordPress

Set this to 3: ‘posts_per_page’ => 3 Add your div in loop require($_SERVER[‘DOCUMENT_ROOT’] . ‘/blog/wp-load.php’); $args = array( // ‘cat’ => 3, // Only source posts from a specific category ‘posts_per_page’ => 3 // Specify how many posts you’d like to display ); $latest_posts = new WP_Query( $args ); if ( $latest_posts->have_posts() ) { while … Read more

Send a mail to specific address in a custom field when a new comment is made on a specific post

It sounds like it’s not working because you’re hooking into comment_post, which is when the comment is created If you change the status of the comment, the comment already exists, and therefore no email is generated. There is a comment status change hook: comment_{$old_status}_to_{$new_status}. It fires anytime a comment’s status changes from one specified status … Read more

Add User Role: Pre-saved in User-Meta [SOLVED]

That’s because you’re not passing an actual ID to get_user_meta, but merely a string of id: $get_portal_number = get_user_meta(‘id’, ‘portal_number’, false); In addition, the third parameter is set to false, which will return an array. You’re passing that value straight to $user->add_role, but that expects a string. You either have to loop over your post … Read more

Redirect to a page for only logged in user

You can make more readable, like. Small notes at the code. As a hint, the template tag is_page() supports an array of values – is_page( [ ‘login’, ‘register’ ] ). add_action( ‘template_redirect’, ‘login_redirect’ ); function login_redirect() { // If user is NOT logged in, doing nothing. if ( ! is_user_logged_in() ) { return; } // … Read more

How to show meta value code HTML after x paragraph

The purpose of echo is sending strings to the output buffer. In your code you are concatenating the result of 4 to the result of the call to echo, which returns nothing. Also, get_post_meta already returns a string so you don’t have to do the type cast. Try: add_filter( ‘the_content’, ‘prefix_insert_post’ ); function prefix_insert_post( $content … Read more

{$key} or $key?

When we perpend $ in any variable then it become Variable variable (Variable vars) like $$name Check this reference for Variable variable. https://www.php.net/manual/en/language.variables.variable.php Here $this->$key will become Variable var because it is about public/private/protected variable of class. So {} in $this->{$key} will set $key vars variable of class

page-slug.php not working but only for specific slug

I thought it might be conflicting with something I had in functions.php, however nothing else was using the name “comics” There is, here: // Arguments $args = array( ‘labels’ => $labels, ‘public’ => true, ‘menu_icon’ => ‘dashicons-book-alt’, ‘hierarchical’ => true, ‘exclude_from_search’ => false, ‘has_archive’ => true, ‘publicly_queryable’ => true, ‘rewrite’ => array( ‘slug’ => ‘comics’, … Read more