How to append to an array and return the results in a filter?

Note this is mostly a PHP programming question about arrays and is better asked on e.g. Stack Overflow. As shown in the docs array_push() acts on the array and takes multiple parameters which get added as array values. It doesn’t add key => value pairs to associative arrays, and it doesn’t return the array itself, … Read more

List all blogs, but exclude the main site

I’ve never used it, but it looks like get_main_site_id is what you want to figure that out, so therefore your code might look like: $mainSiteId = get_main_site_id(); foreach ($user_blogs AS $user_blog) { if ($userblog->site_id != $mainSiteId) { echo ‘<li><a href=”‘.$user_blog->siteurl.'”>’.$user_blog->blogname.'</a></li>’; } }

Undefined offset: 3 in custom function

You assumed get_field would always return images, but what if there are no images to return? $images = get_field(‘fl_gallery’); $image = $images[$no]; The code never checks $images to see if it’s empty, or an error value. On top of that, what if it returned images, but it returned 3 images, and $no is 4? You … Read more

Remove extract from function

It’s very simple: Just assign the value of shortcode_atts() (which is an array) to a variable and use it to access the shortcode attributes in the same way you access the items in any other arrays: $atts = shortcode_atts( array( ‘no’ => 1, ), $atts ); // Use $atts[‘no’] to get the value of the … Read more

Override user-edit.php to design own profile page

Depending on the scope of your project, I would recommend either using ACF (Advanced Custom Fields) which will allow you to create custom fields in your user based on their level, which you can then output into your theme. The outputting part though will require some coding knowledge to do. The other option is to … Read more

Export Form Data to a CSV then send it as an attachment – contact form 7

There are a few things omitted in the above solution, like defining the most params of wp_mail. Also I didn’t want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution. Here’s my take: add_filter( ‘wpcf7_before_send_mail’, ‘add_form_as_attachment’, 10, 3 ); … Read more

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

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