Highlight current post title on a page

That’s easy: You should use $wp_query->current_post to retrieve the index of your custom query. In your case query will work something like this: <ul class=”post-list”> <?php $query = new WP_Query( array( ‘post_type’ => ‘campaign-post’ ) ); while ( $query->have_posts() ) : $query->the_post(); if($query->current_post == 0){ ?> <h1 class=”current”><?php the_title(); ?></h1> <?php } else{ ?> <h1 … Read more

Wildcard search in WP Query

WP_Query will add the % wildcard operators for a LIKE query. Just remove those. As is your query looks like LIKE ‘%\\%rocket\\%% which is not what you want. Try var_dump($query->request); And you can see that for yourself.

filter wp_query result with custom field values

If main_category is a category (custom taxonomy), then you’re querying it wrong. This should go like this: $electronics = array( ‘numberposts’ => -1, ‘post_type’ => ‘article’, ‘main_category’ => ‘electronics’ ); $query_electronics = new WP_Query( $electronics ); If that’s a custom field, use meta_query: $electronics = array( ‘numberposts’ => -1, ‘post_type’ => ‘article’, ‘meta_query’ => array( … Read more

Error with function in functions.php?

These two lines are wrong: add_action(‘wp_ajax_get_data’, mm_get_all_informations); add_action(‘wp_ajax_nopriv_get_data’, mm_get_all_informations); You need to quote the function name: add_action(‘wp_ajax_get_data’, ‘mm_get_all_informations’); add_action(‘wp_ajax_nopriv_get_data’, ‘mm_get_all_informations’); If you had debugging enabled, as you should when you are working, you would have spotted the problem immediately.

Filter post query to only show direct children of category

I assume that by “direct children of category” you mean “posts directly assigned to the category” and not “posts assigned to child categories of the category specified”. The answer is in the Codex: Display posts that have this category (not children of that category), using category id: $query = new WP_Query( ‘category__in=4’ ); http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters Second, … Read more