Show items by user_role

Here is an easy way to check if a user has a role. Note that I used your way of getting the WP_User, but there are others: $user = new WP_User( $item->post_author ); // $user = get_userdata( get_current_user_id()); // another way to get logged in user if ( !user_can($user->ID,’directory_4′) ) { // show items, user … Read more

Enabling XSendFile causes 404 for images on WordPress Multisite / Network

It wasn’t a .htaccess problem, but an apache configuration problem. On a Mac server you need to: compile XSendFile as a universal binary: apxs -cia -Wc,”-arch i386 -arch x86_64″ -Wl,”-arch i386 -arch x86_64″ mod_xsendfile.c and modify the site specific httpd.conf file in /Library/Server/Web/Config/apache2/sites. If you’re having the same problem, I wrote about this on my … Read more

Inserting A Feed and Sidebar into an HTML Page

The typical definition of static page is plain text file, typed by hand or generated by software either. By definition static pages cannot have back-end powered dynamic functionality. There are quite a few approaches to integrating WP (or anything really) with static page, typical being: convert static page to dynamic completely – turn it into … Read more

Querying multiple meta_keys in WordPress SQL query

WordPress Provides a native functions to query these kind of things very easily like WP_User_Query $args = array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => $meta_key1, ‘value’ => $search1, ‘compare’ => ‘LIKE’ ), array( ‘key’ => $meta_key2, ‘value’ => $search2, ‘compare’ => ‘=’ ) ) ); $user_query = new WP_User_Query( $args );

If Elseif Query

This cannot work. It has to look like the following (or similar): <?php if (get_post_meta($post->ID, ‘TourURL’, true)) { ?> <div class=”tourenquiryonline”> <h2>Book or Inquire</h2> This tour can be booked online. </div> <?php } elseif (get_post_meta($post->ID, ‘bhid’, true)) { ?> <div class=”tourenquiryonline”> <h2>Book</h2> This tour can be booked online via the form on the right hand … Read more

How to have post count after each listed category

For showing category count on your loop – foreach($categories as $category) { echo ‘<li><a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in: %s” ), $category->name ) . ‘” ‘ . ‘>’ . $category->name.'</a>&#32;&rsaquo; (‘. $category->count .’)</li>’; } And for showing count with wp_get_archives function, use show_post_count in argument … Read more

Display pages from specific page template

Use get_post_field(‘post_content’, $product_page->ID ) to get the content outside loop. <?php $product_pages_args = array( ‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => ‘page_library_html.php’ ); $product_pages = get_pages( $product_pages_args ); ?> <?php foreach ( $product_pages as $product_page ) { echo ‘<div id=”posts” class=”flex_100″>’; echo ‘<div id=”library_title”><a href=”‘ . get_permalink( $product_page->ID ) . ‘”>’ . $product_page->post_title . ‘</a></div>’; echo ‘<div … Read more

Different image and background color depending on page type

I’ve used WordPress Conditional Tags to add a unique class or id to the containing div of the different page types. This could work well to change the background image/color for different types. Also, WordPress automatically adds a body class to the <body> tag for each page, so that could possibly be hooked into for … Read more