Manipulating a query

You might try to add a posts_where filter in your pre_get_posts hook: function my_pre_get_posts( $q ){ if( $q->is_main_query() ) add_filter( ‘posts_where’, ‘my_posts_where’ ); return $q; } ! is_admin() && add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); where function my_posts_where( $where ){ // your custom replacements on the $where string // … // remove the filter remove_filter( current_filter() , … Read more

Select custom post by meta value

I think you mean a query like this one: $args = array( ‘post_type’ => ‘foo’, ‘meta_key’ => ‘bar’, ‘meta_value’ => ‘pineapple’, ‘posts_per_page’ => 1, ); $query = new WP_Query( $args ); You can check out further information here on meta queries in WP_Query. If you only want to check if there exists such a post, … Read more

WPMU site in subdirectory: When I clone a site with NS Cloner Pro plugin, how do I remove the subdirectory from the URL?

Here is the answer that I provided through official support and the ultimate confirmed solution was to move the installation to the domain root and eliminate /new/ altogether; full explanation: Thanks for your question. Hopefully I understand your scenario correctly. Have you previously been creating subsites the normal way? What do their paths look like? … Read more

How to bring custom meta boxes to custom post types?

You can do something like this: function wpse_61041_add_custom_box() { //Place your custom post types in the array $post_types = array ( ‘post’, ‘page’, ‘another_custom_post_type’ ); //Then loop through all post types and add meta boxes to them foreach( $post_types as $post_type ) { add_meta_box( ‘wpse_61041_sectionid’, ‘Does this page is in Englsih?’, ‘wpse_61041_inner_custom_box’, $post_type, ‘side’, ‘high’ … Read more

How to mix pages and sub-categories in a url

I don’t think so. Why not try something like this: A permalink structure like this: /%category%/%postname%/ Category: Windows Sub-Category: Serenity Create a post and assign it to “Serenity” (sub-category), and publish it. The post’s URL would now look just the way you want it to: http://site.com/windows/serenity/post-name/ and most importantly it should work the way you … Read more

How to show a feed that requires user/pass within a sidebar widget?

There is a solution as described here where you can put code at the top of wp-includes/feed-rss2.php to authenticate that the requester is a registered WordPress user. A better solution is to add it to your theme’s functions.php file: function my_check_feed_auth() { if (!isset($_SERVER[‘PHP_AUTH_USER’])) { header(‘WWW-Authenticate: Basic realm=”RSS Feeds”‘); header(‘HTTP/1.0 401 Unauthorized’); echo ‘Feeds from … Read more

How is a URL getting mapped to a page template

I have done something similar by adding a rewrite rule add_rewrite_rule( “users”, “index.php?fea_users”, ‘top’); add_filter( ‘query_vars’, array($this, ‘query_vars’) ); add_filter( ‘template_include’, array($this, ‘template_include’), 1, 1 ); function query_vars( $query_vars ) { $query_vars[] = “fea_users”; return $query_vars; } function template_include( $template ) { global $wp_query; if ( isset($wp_query->query[“fea_users”]) ) { // return any php file here … Read more

Error trying import one category on page

As per the codex query_posts Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. Double Note: query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the … Read more