• I am creating a wordpress template. I added a meta box on front-page.php. I wish that the user has the choice to show or not his achievements on the homepage. If he wants to show his achievements, he can choose which achievement he wants to display in the homepage among the achievements present in the portfolio. I specify that ‘capacity_portfolio’ is custom post type.

    <?php 
    	$args = array( 'post_type' => 'capacity_portfolio'); 
    	$loop = new WP_Query( $args ); 
    	if ($loop->have_posts()) : while ( $loop->have_posts() ) : $loop->the_post(); 
    	the_title(); 
    	endwhile; 
    	endif;
    ?>

    a strange thing happens: all the meta boxes on the page are suplicated, see figure here. help me please !

    When I replace the custom post type ‘capacity_portfolio’, by the post type ‘page’, it works, but when I replace it with the post type ‘post’ it does not work. I said that when I erase this piece of code, the metabox works properly.

    • This topic was modified 6 years, 7 months ago by anUser.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Please check again your custom post type name, I used your code with post type product of WooCommerce to test and it works so well.

    <?php 
    	$args = array( 'post_type' => 'product'); 
    	$loop = new WP_Query( $args ); 
    	if ($loop->have_posts()) : 
    		while ( $loop->have_posts() ) : 
    			$loop->the_post(); 
    			the_title(); 
    		endwhile; 
    	endif;
    ?>
    Thread Starter anUser

    (@anuser)

    Thank you for your answer. There is no problem with the name of the custom post type. Otherwise, I tried with the post type ‘page’, it works, but when I try with post type ‘post’ or custom post type ‘capacity_service’, I have the same problem …

    I specify that I am in a meta box. I am not on a template (example: page.php).

    • This reply was modified 6 years, 7 months ago by anUser.
    • This reply was modified 6 years, 7 months ago by anUser.
    Thread Starter anUser

    (@anuser)

    <?php
    	$args = array('post_type' => 'capacity_portfolio', 'orderby' => 'modified'); 
    	$pages = get_posts( $args );
    	foreach ( $pages as $page ) : setup_postdata( $page ); 
    	
    	echo $page->post_title; 
    	
    	endforeach; 
        wp_reset_postdata();

    The problem is solved…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Loop cutsom post type in meta box’ is closed to new replies.