making random query button using $_GET

You cannot use the direct class methods have_posts() or the_post() unless you’re working with the main query. In order to modify the main query you must use query_posts. If you want to create a new query object you need to call those methods from the new query object as Rarst showed in his example. So … Read more

get_meta_data within a loop

query_posts() is for main query, it would be more wise to use get_posts() function to get you events. // Modify get_posts args for your needs $events = get_posts( array ( ‘post_type’ => ‘events’ ) ); if ( $events ) { echo ‘<ul>’; foreach ( $events as $event ) { $event_date = get_post_meta( $event->ID, ‘event-date’, true … Read more

How do I make archives.php for one category only?

First: don’t use query_posts(), ever. Second, to create a category archive index page template for a specific category, refer to the Codex entry for the Template Hierarchy: category-{slug}.php category-{id}.php category.php archive.php index.php So, if you have a category, ‘foobar’, with a category ID of 1, you could do either of the following: category-foobar.php category-1.php And … Read more

Custom category search box for WordPress

In every template file of your theme, even in the header.php you can put <?php $term = null; $btn = __(‘Search’); if ( is_category() ) { $term = get_queried_object(); } ?> <form method=”get” id=”search_form” action=”<?php echo home_url(); ?>”> <div> <input type=”text” value=”” name=”s” id=”s” /> <?php if ($term) { $btn = sprintf( __(‘Search in %s’), … Read more

Exclude posts with empty post_content in wp_query

This isn’t possible with a standard WP query, and you’ll have to leverage the use of posts_where before the WP_Query is called. function the_dramatist_filter_where($where=””){ $where .= ” AND trim(coalesce(post_content, ”)) <>””; return $where; } In the above, we’re simply only selecting posts where the column post_content isn’t empty. Then add the filter. add_filter(‘posts_where’, ‘the_dramatist_filter_where’); Now … Read more

Multiple post type queries (with specific arguments for each)

Could you do something like this? <?php $args = array( ‘post_type’ => array(‘post’,’movie’,’actor’), ‘posts_per_page’ => ’20’, ); query_posts( $args ); while ( have_posts() ) : the_post(); global $post; if (($post_type == ‘movie’) && (get_post_meta($post->ID, ‘meta_key’, true) == ‘your-value’)) { // Display your content for Movie Post Type with meta value set } else if (($post_type … Read more

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