changing post type in loop query

To have the first code block to work on a secondary query, you’d need: function customize_customtaxonomy_query ( $query ) { $query->set(‘post_type’, array(‘business’) ); // return $query; // not necessary; actions do not return anything } add_action( ‘pre_get_posts’, ‘customize_customtaxonomy_query’ ); $q = new WP_Query($args); And you should remove it afterwards so that it doesn’t interfere with … Read more

Custom post type blog pagination conflict

Thank you to Milo for pointing me to the pre_get_posts hook. That was exactly what I needed. Here is my updated code: Archive page code <?php get_header(); get_template_part( ‘include/content’, ‘head’ ); ?> <div class=”postcontent nobottommargin<?php if( semi_option( ‘blog_sidebar’ ) == ‘left’ ) { echo ‘ col_last’; } ?> clearfix”> <?php if ( have_posts() ) : … Read more

Delete attachment with post

This is the right hook to do this: add_action(‘before_delete_post’, ‘delete_post_attachments’); function delete_post_attachments($post_id){ global $wpdb; global $post_type; if (!$post_type == ‘bkroadkill’) return; $args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘any’, ‘posts_per_page’ => -1, ‘post_parent’ => $post_id ); $attachments = new WP_Query($args); $attachment_ids = array(); if($attachments->have_posts()) : while($attachments->have_posts()) : $attachments->the_post(); $attachment_ids[] = get_the_id(); endwhile; endif; wp_reset_postdata(); … Read more

How to use wp query posts with current post meta value in text widget

Your question is a bit hard to read, but if I understand you on a single post page this should work: $obj = get_queried_object(); if (‘WP_Post’ === get_class($obj)) { $cellar = get_post_meta($obj->ID,’cellar_slug’,true); if (!empty($cellar)) { $cellars = new WP_Query( array( ‘post_type’ => ‘post’, ‘numberposts’ => -1, ‘posts_per_page’ => ‘1’, ‘meta_query’ => array( array( ‘key’ => … Read more