Knowing the total number of posts before to get into the loop

functions.php: function wpse8170_get_posts_count() { global $wp_query; return $wp_query->post_count; } index.php: if (have_posts()) : echo ‘<h1>’ . wpse8170_get_posts_count() . ‘ Posts Found</h1>’; while ( have_posts() ) : the_post(); //… endwhile; endif;

Query both first_name and last_name from wp_usermeta at the same time

I can’t find a clean, native way to pull this data. There are a couple of ways I can think of to do this: First, something like: $sql = ” SELECT user_id,meta_key,meta_value FROM {$wpdb->usermeta} WHERE ({$wpdb->usermeta}.meta_key = ‘first_name’ OR {$wpdb->usermeta}.meta_key = ‘last_name’)”; $ansatte = $wpdb->get_results($sql); var_dump($sql); $users = array(); foreach ($ansatte as $a) { $users[$a->user_id][$a->meta_key] … Read more

Should I write a PHP function in home.php?

At the risk of getting voted down by everybody else here who thinks this is OK. I say: No, you shouldn’t define functions in template files. This should be considered bad practice. Let’s have a look at the documentation: Functions File Explained. The functions file behaves like a WordPress Plugin, adding features and functionality to … Read more

Get author full name

Try the following: <?php $fname = get_the_author_meta(‘first_name’); $lname = get_the_author_meta(‘last_name’); $full_name=””; if( empty($fname)){ $full_name = $lname; } elseif( empty( $lname )){ $full_name = $fname; } else { //both first name and last name are present $full_name = “{$fname} {$lname}”; } echo $full_name; ?>

WordPress PHP version requirements

WordPress will change its requirements to use a higher version of PHP when the following cases are met: A significant majority of users are running 5.3.0 or above A major release cycle release approaches The code/lead developers involved all agree the above two are fulfilled Sadly, the first entry results in a vicious loop, and … Read more

PHP Catchable fatal error: Object of class WP_Error could not be converted to string

Line 58 as the error indicates is this line: $parent_term = get_term_by(‘ID’,$term_id, $taxonomy); $term_parents = $delimiter.”<a href=\””.get_term_link($parent_term->slug,$taxonomy).”\” title=\””. $parent_term->name .”\” >”. $parent_term->name .”</a>” .$child_terms; And our error is: Object of class WP_Error could not be converted to string Which means that one of those things being appended is not a “string”, but actually a WP_Error … Read more

Multiple is_page() in page.php

You can pass an array of IDs to is_page instead of using multiple is_page: if( is_page( array( 11, 22, 33, 44 ) ) ) { // Your code } Also, if you are using it in a loop, you should consider this note: Due to certain global variables being overwritten during The Loop, is_page() will … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş