Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?

The Problem I think there’s a typo in there: The name of the filter is posts_fields not post_fields. That could explain why the title2 field is unknown, because it’s definition isn’t added to the generated SQL string. Alternative – Single filter We can rewrite it to use only a single filter: add_filter( ‘posts_orderby’, function( $orderby, … Read more

Why is “/page/2/” not working?

Found the answer: After a looong day debugging thru wordpress core, I managed to solve this issue. Basicly, you CANT have a PAGE and a CUSTOM POST TYPE with the same name. If you do, the permalink rewrite rules will get confused and trigger a 404. A very simple solution I’m using is: The page … Read more

Query by post title

You can use either search parameter of wp_query : Code $args = array(“post_type” => “mytype”, “s” => $title); $query = get_posts( $args ); Or you can get posts based on title throught wpdb class: global $wpdb; $myposts = $wpdb->get_results( $wpdb->prepare(“SELECT * FROM $wpdb->posts WHERE post_title LIKE ‘%s'”, ‘%’. $wpdb->esc_like( $title ) .’%’) ); Than you’ll … Read more

What is appropriate flow for custom data from URL in WP_Query?

I think the WP function you are looking for is add_rewrite_tag. It aims to add custom GET params to your URL and include it automatically in query_vars. For example, you can add the following to the init hook : add_rewrite_tag(‘%person%’,'([^&]+)’); For a url like http://example.com?person=joe, the global $wp_query will have $wp_query->query_vars[‘person’] = ‘joe’ You can … Read more

Passing and retrieving query vars in wordpress

I’m almost sure that author is built-in, so use something like author_more. You will need to add that var to query_vars first. Example: // add `author_more` to query vars add_filter( ‘init’, ‘add_author_more_query_var’ ); function add_author_more_query_var() { global $wp; $wp->add_query_var( ‘author_more’ ); } Then on your more-author-posts.php template call it like this: if ( get_query_var( ‘author_more’ … Read more

Query posts only with featured image

When running the importer, you must check the checkbox to download and import all media/attachments. If you do not, the posts will still have a featured image set, but the attachment they refer to will be invalid, and any attempt to call the_post_thumbnail will fail. Using your code you would get just the post title, … Read more

meta_query ‘compare’ => ‘IN’ not working

There’s no easy way to search serialized values in a meta query. If the list of values isn’t crazy long, potentially you could set up multiple meta queries: ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘system_power_supply’, ‘value’ => ‘single’, ‘compare’ => ‘LIKE’, ), array( ‘key’ => ‘system_power_supply’, ‘value’ => ‘redundant’, ‘compare’ => ‘LIKE’, … Read more

How to use a custom post type archive as front page?

After you have set a static page as your home page you can add this to your functions.php and you are good to go. This will call the archive-POSTTYPE.php template correctly as well. add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page($wp_query){ //Ensure this filter isn’t applied to the admin area if(is_admin()) { return; } if($wp_query->get(‘page_id’) == get_option(‘page_on_front’)): $wp_query->set(‘post_type’, ‘CUSTOM … Read more

tech