Pagination shows 404 after a certain number of pages

The problem is that WordPress is executing the main query before your custom query (and the main query is based on the default post type only). You can intercept the main query, modify it, and then use it like so function add_blog_post_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘post_type’, array(‘post’, … Read more

Load more AJAX on WP Query

if you want to use ajax in wordpress you must have to follow these step: 1) first make your js file like main.js. 2) localize it in functions.php with wp_localize_script(). wp_enqueue_script( ‘main.js’, get_template_directory_uri().’/js/main.js’, array( ‘jquery’ ) ); wp_localize_script( ‘main.js’, ‘ajax_object’, array(‘ajax_url’ => admin_url(‘admin-ajax.php’)) ); 3) make your javascript or jquery code to run your query … Read more

Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?

Hi @janoChen: If you have a choice, go with WP_Query. Both of the other functions (query_posts() and get_posts()) call WP_Query indirectly. The former is designed to allow you to modify the main query after the standard query has already been run, for example when you want a second loop. But query_posts() affects global variables and … Read more

Sort posts alphabetically by custom field value, insert divider between different letters

Try this: <ul class=”list-ensemble”> <?php query_posts(‘post_type=person&post_status=publish&meta_key=last_name&orderby=meta_value&order=ASC’); $current_letter=””; if ( have_posts() ) while ( have_posts() ) : the_post(); $last_name = get_post_meta( $post->ID, ‘last_name’, true ); $letter = strtolower( substr( $last_name, 0, 1 ) ); if ( $letter != $current_letter ) { $current_letter = $letter; ?> <li class=”letter”> <img src=”https://wordpress.stackexchange.com/questions/10561/<?php echo $letter; ?>.jpg” alt=”<?php echo $letter; ?>” … Read more

Identify which loop you are hooking into; primary or secondary?

Just a quick update that a new method is_main_query() has been introduced in WP 3.3. Example: add_action( ‘pre_get_posts’, ‘foo_modify_query_exclude_category’ ); function foo_modify_query_exclude_category( $query ) { if ( $query->is_main_query() && ! $query->get( ‘cat’ ) ) $query->set( ‘cat’, ‘-5’ ); } Resources: WPDevel: New API in 3.3: is_main_query() Codex reference: is_main_query() Related Trac Ticket #18677

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