Inserting random posts

Combining two different custom post types in one single query, and still being able to control the number of each type of posts to be displayed can be a little tricky. If one single query is used with post_type = array( ‘type1’, ‘type2’…. ), you have to set posts_per_page to a considerably high number. Which … Read more

Loop to get current parent page “content” and his children content

Super basic example that gets the parents title and content and then the title and content for each child page. This is not just the loop, but an entire page template. <?php include_once( ‘header.php’ ); ?> <?php $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array(‘post_type’ => ‘page’)); ?> <?php if ( have_posts() ) : while ( … Read more

Conditional Check in The Loop’s Parameters

I would change $args = array( ‘category_name’ => $category, ‘showposts’ => $numposts, ‘order’ => $order ); to $args = array( ‘showposts’ => $numposts, ‘order’ => $order ); if ( $category ) $args[‘category_name’] = $category; This way you never pass an empty category_name parameter as a query arg.

Custom Taxonomy + JQuery Tabs

This should work, but it’s not tested <div id=”tabs”> <ul id=”tab-menu”> <?php $terms = get_terms(‘category’); global $wpdb; $posts = array(); if ( is_array($terms) && ! empty($terms) ) { $active = null; foreach ( $terms as $i => $term ) { $ids = $wpdb->get_col( $wpdb->prepare(“SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d”, $term->term_taxonomy_id )); $articles_count = … Read more

Get query result before posts are displayed?

You can use the the_posts filter to loop through the results before they get returned. Proof of concept: function test_the_posts($a) { var_dump($a); die; } add_action(‘the_posts’,’test_the_posts’); I am fairly certain (though I haven’t tested it) that you could pretty easily break pagination and probably other things by fiddling with that, so be careful.

Placing the content of one post in two side by side columns, newspaper style

Turns out there are specific CSS properties for columns: Here’s what worked for my case: .featured { -moz-column-count: 3; -moz-column-width:245px; -moz-column-gap: 40px; -webkit-column-count: 3; -webkit-column-gap : 40px; -webkit-column-width:245px; -moz-column-rule-color: #ccc; -moz-column-rule-style: solid; -moz-column-rule-width: 1px; -webkit-column-rule-color: #ccc; -webkit-column-rule-style: solid ; -webkit-column-rule-width: 1px; } And two refs for several other ways to go about it. ADVANCED 2 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)