Why can’t I call a (member) function from within a foreach?

You use $mediatags variable in global scope as array in your loop, and then try to use the same variable as object in your function. You override your global $mediatags variable in your loop. Try to use following code: foreach($new_name_for_mediatags_array as $mediatag){ $args=”media_tags=animals&numberposts=10&return_type=li&size=thumbnail”; $media_items = get_attachments_by_media_tags($args); echo $media_items; };

Get categories names as an array to use it in theme settings

Thanks Michael for the tip. I finally got it. The solution is as follows: $options[] = array( “section” => “zzz”, “id” => HS_SHORTNAME . “_multicheckbox_inputs”, “title” => __( ‘Multi-Checkbox’, ‘hs_textdomain’ ), “desc” => __( ‘Some Description’, ‘hs_textdomain’ ), “type” => “multi-checkbox”, “std” => ”, “choices” => my_list_cats() ); And in functions.php: function my_list_cats() { $cats … Read more

Editing a PHP file to include a small text piece on every page

You should provide your code when asking this type of question. Here is an example of a header.php file. Look at the code and see how it’s done: <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset=”<?php bloginfo( ‘charset’ ); ?>” /> <title> <?php global $page, $paged; wp_title( ‘|’, true, ‘right’ ); bloginfo( ‘name’ ); … Read more

Error while setting role

You have to use just $current_role variable instead of $current_role[0], because call get_user_meta( $author->ID, ‘wp_capabilities’ ); will return you array with roles as keys. <?php add_action( ‘save_post’, ‘update_roles’ ); function update_roles( $post_id ) { if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return $post_id; // Get the author $author = wp_get_current_user(); // Set variables for … Read more

How Can I Edit the Registration Code?

You can use the plugin AWeber Web Form Plugin. Just enable aweber optin checkbox for registration. Or If you want to do it yourself checkout the article http://adamcap.com/2011/10/how-to-integrate-aweber-and-wordpress-registration-without-a-plugin/

Passing a variable from a FOREACH loop in a link

This is more of a basic PHP question, but still it’s somewhat important. Inside your foreach loop, $category is a locally-defined variable. That’s to say, it only exists inside the foreach loop. So if you have foreach ( $categories as $category ) { // You can use $category all you want in here } // … Read more