1

In order to add a personilized sidebar for costom posts I define a shortcode using add_shortcode ( >name shortcode< ) and I recall the shortcode in sidebar using a plugin. In the sidebar I must show a second menu under the first for some specific custom post type. So I define a $sidebar for all custom posts and write the following code to select some specific custom posts to add the second menu to them:

$args = array(
        'post_type' => 'custom_post',
        'post__in' => array( >custom post ids separeted by comma< )
    );
    
    $posts = get_posts($args);
    
    $sidebar = $logo.$menu.$box;
    
    foreach ($posts as $p) {
        $sidebar = $sidebar.$menu1.$box1;
    }
    
    $out = null;

    return $sidebar;

The problem is that the code add the second menu to all custom posts and not only on the array of costom post ids. What's wrong?

4
  • 1
    Please include the function name, and where/how the function is called.
    – Caleb
    Commented Jun 8, 2023 at 14:14
  • I define a shortcode using add_shortcode ( >name shortcode< ) and I recall the shortcode in sidebar using a plugin
    – Gianluigi
    Commented Jun 8, 2023 at 14:17
  • 1
    Please add this information to your question.
    – Caleb
    Commented Jun 8, 2023 at 14:24
  • Where/how are you building the array of posts for 'posts__in'? Are we certain that it's giving the correct information. Commented Jun 8, 2023 at 19:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.