Support

Account

Home Forums General Issues Post_object with loop

Unread

Post_object with loop

  • I need help. I created shortcode to display post title and permalink to post with another category. But I see only one value, how to change to show list of post which are connected with this post. My function:

    function my_shortcode() {
    $main_id=get_the_ID();
    $args = array(‘category_name’ => ‘pp’, ‘posts_per_page’ => 500 );
    $myposts = get_posts( $args );
    $usedon_link = get_permalink($mypost->ID);
    $usedon = get_the_title($mypost->ID);

    foreach ( $myposts as $mypost ){
    $compare_id=get_field_object(‘my_field’, $mypost->ID);

    if($compare_id[‘value’]){

    foreach($compare_id[‘value’] as $pp)
    {

    if ($main_id==$pp->ID){

    return “$mypost->post_title“;

    }
    }
    }
    }

    }
    wp_reset_postdata();

    add_shortcode( ‘my’, ‘my_shortcode’ );

    Thank you!

Viewing 1 post (of 1 total)

The topic ‘Post_object with loop’ is closed to new replies.