trouble modifying code for custom post type

Hello,
I have been using this piece of code to move content from one page and display it on another. It works fantastic. However I am struggling to figure out how to modify this code so that it works on a custom post type ("products") vs. a regular page. Is there a CPT expert out there who can help me out? Thanks.

// Enable shortcode to place MAIN CONTENT from one page on another [my_content id="" title=true /]

function get_post_page_content( $atts ) {
            extract( shortcode_atts( array(
                'id' => null,
                'title' => false,
            ), $atts ) );

            $the_query = new WP_Query( 'page_id='.$id );
            while ( $the_query->have_posts() ) {
                $the_query->the_post();

                    the_content();
            }
            wp_reset_postdata();

        }
        add_shortcode( 'my_content', 'get_post_page_content' );
  • Rupok

    Hi eschmidtke, hope you had a wonderful day.

    I've modified your code a bit. Can you try the following code and check if it works?

    function get_post_page_content( $atts ) {
                extract( shortcode_atts( array(
                    'id' => null,
                    'title' => false,
                ), $atts ) );
    
                $args=array(
                  'page_id' => $id,
                  'post_type' => 'products'
                );
    
                $the_query = new WP_Query( $args );
                while ( $the_query->have_posts() ) {
                    $the_query->the_post();
    
                        the_content();
                }
                wp_reset_postdata();
    
            }
            add_shortcode( 'my_content', 'get_post_page_content' );

    I've not tested this, but it should work. If it doesn't, please let us know. We will be glad to check further.

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.