Get query results with a page title

There’s a problem with your get_page_by_title() usage, since you assume it returns the page ID, but it returns an object/array or null. You also have to tell it about your custom post type. I also assume your products are stored as custom post type cars. Please try the following with a given product title (untested): … Read more

How to set parameters for search loop?

You can modify search query and set your parameters with the help of pre_get_posts. Like this. function wpse_custom_get_posts( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search() ) { $query->set( ‘post_status’, ‘publish’ ); } } add_action( ‘pre_get_posts’, ‘wpse_custom_get_posts’, 1 );

2 queries with counters

On the advise of Robert and Pieter I rewrote the loops using WP_Query instead of query_posts. It works now. Thanks guys. Here’s the code: <ul class=”tabs”> <li class=”tab-link current” data-tab=”tab-1″>Most Popular</li> <li class=”tab-link” data-tab=”tab-2″>Recent</li> </ul> <div id=”tab-1″ class=”tab-content current”> <div class=”slider”> <div class=”slide”> <?php $count = 0; $query = new WP_Query( array( ‘meta_key’ => ‘post_views_count’, … Read more

Display all attached image of every post of custom post type and link to original post

You have two issues here. The use of $image->ID in this line wp_get_attachment_image($image->ID, ‘video-thumb’); This will give you the following error: NOTICE Error: [8] Undefined variable: image In all honesty, I think that should actually be $post->ID get_permalink() returns the permalink to the current post, which in this case is the image. If you want … Read more

how to load posts to a custom post template after using template_redirect or template_include

here is the full code to force change theme by a reserved wordpress parameter add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); function my_pre_get_posts($wp_query) { global $wpdb; // Confirm request is main query if(!$wp_query->is_main_query()) { return; } // Get post name from query $post_name = $wp_query->get(‘pagename’); // Get post type from database $post_type = $wpdb->get_var( $wpdb->prepare( ‘SELECT post_type FROM … Read more

show custom category posts from a custom post type

You should need to do any custom querying on taxonomy-subject.php, just use the normal loop api. WordPress will build a query for you. As for your question: $args = array( ‘post_type’ => ‘documents’, ‘posts_per_page’ => 20, ); WP_Query doesn’t take a second argument to its constructor. All its seeing is the arguments above. You’re asking … Read more

How to add WordPress featured image via SQL

I can tell how to do it with WordPress functions, which is quite easy and you won’t lose any important stuff: Upload the default.jpg image using WordPress media manager. Note the ID of the image. Get all posts from your custom post type and run set_post_thumbnail() for each one. Example: add this code to functions.php … Read more