Blog

Retrieve Pages by Path or Template in WordPress

By Template: $pages_using_template = get_pages(array( ‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => ‘template-press-release-list.php’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘page’, ‘hierarchical’ => 0 //because page looking for could have a parent – without this only gets top level pages. )); Check if got anything and use it from query above: if($pages_using_template && count($pages_using_template)…

WordPress Menu Functions

wp_get_nav_menu_items( string $menu, array $args = array() ) Returns an array of menu items. $menu parameter is slug or id of Menu created in WordPress. $args is from here: get_posts, which isn’t very helpful for filtering what menu items you want to display.  This function returns an array that you…

Category Template Tags

The following functions can be used on the category.php template to display information about the current category. Display Current Category Title on category.php: <?php single_cat_title(); ?> <?php single_term_title(); // more generic – can be used on archive.php too ?> Display Current Category Description: <?php echo category_description(); ?> Get Current Category…

Handy WordPress Functions

A collection of WordPress functions I use often. Link to Home: <?php home_url( $path_relative_to_root, $opt_scheme_http_https ); ?> <?php echo esc_url( home_url( ‘/’ ) ); ?> Include another php file: get_template_part($slug, $name); *File name separated on ‘-‘ between two inputs to function. So if named include-content-blocks.php call is: get_template_part(‘include’, ‘content-blocks’); Custom…

WP_Query – Order by multiple custom fields

The Code $args = array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘board’, ‘meta_query’ => array( ‘last_name’ => array(‘key’ => ‘last_name’), ‘first_name’ => array(‘key’ => ‘first_name’), ),’orderby’ => array( ‘last_name’ => ‘ASC’, ‘first_name’ => ‘ASC’ ), ‘nopaging’ => true ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while…

How Did They Get My WordPress Username?

I currently manage over 50 WordPress websites and have the ‘Limit Login Attempts’ plugin set to send an email whenever anyone tries to log into one of these sites and fails. It doesn’t take long for a new WordPress website to go through its first brute force login attack. When…

Comparing WordPress Hosting Companies

Below are slides from my WordCamp Milwaukee 2014 presentation entitled “Comparing WordPress Hosting Companies”. I discuss my experiences hosting over 50 WordPress websites with hosting companies such as WP Engine, Flywheel, Pressable, HostGator, Site5 and SiteGround, comparing each host’s Security, Backups, Support, Speed and Price. I hope this information helps…

Gentle Introduction to Google Analytics

Have you ever wondered how many people view your website and how your website is used? If so, you might be surprised to know there is a way to view this data if your website was set up with the free Google Analytics service. All my clients’ websites have this…