Tag Info

Hot answers tagged

3

You are looking at type casting: http://php.net/manual/en/language.types.type-juggling.php What the code does is caste the value returned by get_option() to an array. It is being done so that array_merge() works correctly and doesn't trigger warnings/errors. That much is pure PHP and is off-topic. The only reason I chose to answer rather than to post a ...


3

Here is how I would solve your problem since $authordata is not a variable that I recognize as a WordPress global. function display_post_via_specific_author( $nicename ) { // Grab the user by `user_nicename` $author = get_user_by( 'slug', $nicename ); $posts = get_posts( array( 'author' => $author->ID, ...


3

Use strtok(): return strtok( get_the_title(), ',' ); You could also use my function utf8_truncate(). This is a little bit more flexible and it can handle long strings without a comma.


3

Add the following code to your functions.php: function allow_contributor_uploads() { $contributor = get_role('contributor'); $contributor->add_cap('upload_files'); } if ( current_user_can('contributor') && !current_user_can('upload_files') ) { add_action('admin_init', 'allow_contributor_uploads'); } This will add the upload_files ...


2

Remove the ! before is_page(). The function is_page() is built into WordPress and only tests if the post being viewed is a page or not. The ! stands for "not", so if you take it out, the code will only return true on that part if it is a page.


2

Per the Codex, is_author() checks to see if you're on an Author Archive page (ie, a page listing all the posts/pages/etc that a given user has authored). If you're on any other type of page, is_author() will return false. What you're looking for sounds more along these lines: if ( in_the_loop() ) { get_currentuserinfo(); print ( get_the_author() ...


1

I'd try to use author IDs rather than the username: if ( get_current_user_id() == get_the_author_meta( 'ID' ) ) { echo "It is my site."; else { echo "It's not my site"; }; References get_current_user_id get_the_author_meta


1

This is not a specific WordPress question, is a topic in php coding. You can add html markup inside the echo in your function, like the follow example: function show_today_date() { echo '<div class="example">' . date( get_option( 'date_format' ) ) . '</div>'; } add_shortcode( 'showtodaydate', 'show_today_date' );


1

Use this function: function user_id_exists($user){ global $wpdb; $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users WHERE ID = '$user'")); if($count == 1){ return true; }else{ return false; } } Usage: if(user_id_exists(1)){ //it does exists } else { //it doesn't }


1

Try to replace if ( $url !== 'http://www.mydomain.net/' ) with if ( !is_home() ), which is WP's own function that checks if it's the blog's front page.


1

What you need to do to achieve this is to provide the second parameter of wp_list_comments(), which would be $comments and is described like this: (array) (optional) Array obtained by get_comments query. Default: The default return of get_comments. Which actually makes it clear what you need to do, which would be utilizing get_comments(). Below ...


1

Your code actually looks good, according to the WooCommerce Documentation. It may simply be related to usage in a child theme, but I think that would still work. For reference, here is what I use to replace the default WooCommerce CSS files. This only disables the "general" styling (colors, buttons, etc) but keeps the structuring and responsive design. ...


1

i tried the below code and it worked. add this to your functions.php register_nav_menus(array( 'top-menu' => __('Menu1', 'twentyfourteen'), 'side-menu' => __('Menu2', 'twentyfourteen'), 'footer-menu' => __('Menu3', 'twentyfourteen') ) ); function my_walker_nav_menu_start_el($item_output, $item, $depth, $args) { $menu_locations = ...



Only top voted, non community-wiki answers of a minimum length are eligible