Site icon Hip-Hop Website Design and Development

Why are my wp_query args being ignored if post_type = CPT

I’ve just a few totally different CPTs setup; ‘jobs’, ‘occasions’, ‘merchandise’.
They’re being displayed on numerous pages of the positioning, in sidebar or footer areas.

Utilizing the next code, my CPT will get output, however all $args are ignored besides ‘post_type’. Posts are output as if ‘posts_per_page’ => -1.

If I go away ‘post_type’ empty, then weblog posts are loaded and the entire args work as anticipated.

I’ve the identical downside irrespective of which CPT I take advantage of for ‘post_type’. Instance of ‘jobs’ beneath:

<?php
$args = array(         
    'post_type' => 'jobs', 
    'posts_per_page' => 3,
    'post_status' => 'publish',
    'order' => 'DESC',
    'orderby' => 'menu_order'
);
$wp_query = new WP_Query($args);
whereas ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
    
// POST CONTENT
    
<?php endwhile; wp_reset_query(); ?>

CTP’s are setup as follows:

add_action( 'init', 'm_jobs_init' );

operate m_jobs_init() {
$labels = array(
    'identify'               => __( 'Jobs' ),
    'singular_name'      => __( 'Job' ),
    'menu_name'          => __( 'Jobs' ),
    'name_admin_bar'     => __( 'Jobs' ),
    'add_new'            => __( 'Add Job' ),
    'add_new_item'       => __( 'Add New Job' ),
    'new_item'           => __( 'New Job' ),
    'edit_item'          => __( 'Edit Job' ),
    'view_item'          => __( 'View Job' ),
    'all_items'          => __( 'All Jobs' ),
    'search_items'       => __( 'Search Jobs' ),
    'parent_item_colon'  => __( 'Dad or mum Job' ),
    'not_found'          => __( 'No Jobs Discovered' ),
    'not_found_in_trash' => __( 'No Jobs Present in Trash' ),
);

$args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'show_in_nav_menus'  => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'jobs' ),
    'capability_type'    => 'publish',
    'has_archive'        => true,
    'hierarchical'       => true,
    'menu_position'      => null,
    'helps'           => array( 'title', 'editor', 'creator', 'thumbnail', 'excerpt', 'page-attributes','post-formats' )
);

register_post_type( 'jobs', $args );
}

Extra notes as beneath:

I’ve one pre_get_posts filter that adjustments the output on the archive web page. I attempted eradicating that however nothing modified with this question.

I’ve additionally been by means of and checked some other wp_query loops are closing with wp_reset_postdata(); however to no avail.

I’ve additionally run var_dump($wp_query); which I can see would not look proper, however undecided the place errors are coming from. A truncated model reads:

object(WP_Query)[8153]
  public 'question' => 
    array (measurement=5)
      'post_type' => string 'jobs' (size=4)
      'posts_per_page' => int 3
      'post_status' => string 'publish' (size=7)
      'order' => string 'DESC' (size=4)
      'paged' => int 1
  public 'query_vars' => 
    array (measurement=65)
      'post_type' => string 'jobs' (size=4)
      'posts_per_page' => int -1
      'post_status' => string 'publish' (size=7)
      'order' => string 'ASC' (size=3)
      'paged' => int 1

The place does this second block of knowledge come from? This has 'posts_per_page' => int -1 and 'order' => string 'ASC' which seems to be prefer it is perhaps the reason for the problem.