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

Running a custom query inside another cpt single and trying to grab a variable

Does this work? global $post; // make sure the post object is available $slug = $post->post_name; // get the slug // insert the slug into your query $args = array( ‘post_type’ => ‘client_prop’, ‘posts_per_page’ => 10, ‘tax_query’ => array( array( ‘taxonomy’ => ‘prop_neighborhood’, ‘field’ => ‘slug’, ‘terms’ => $slug, ) ) );