• Hi wordpress people.

    I have a query and new with arrays so it maybe simple for someone else to solve.

    I have a custom post type for projects and products on my site. I have created a a box on each project page that lists all the products. The user is able to tick as many boxes (checkboxes) as they want to assign the project to more than one product.

    For the boxes ticked the ID of the product is saved in to the custom meta value os_linkto_product. e.g. 45,109,25

    On single-product.php I want a scrolling list of all projects assigned to the product we are on.

    So here is my loop to show all projects:-

    <ul>
    <?php
    	$args = array
    	(
    		'post_type'		=> 'projects',
    
    		'orderby'		  => 'menu_order',
    		'order'			=> 'ASC',
    		'posts_per_page'   => -1
    	);
    	$posts = get_posts($args);
    
    	if (count($posts) > 0)
    	{
    
    		foreach ($posts as $post)
    		{
    			setup_postdata($post);
    
    			?>
    			<li>
    				<a href="<?= get_permalink($post->ID); ?>"><?= get_the_first_image($post->ID, 'landscape'); ?></a>
    				<div>
                    	<h2><a href="<?= get_permalink($post->ID); ?>"><?= $post->post_title; ?></a></h2>
    					<p><a href="<?= get_permalink($post->ID); ?>"><?= substr(strip_tags($post->post_content), 0, 150); ?>...</a></p>
    				</div>
    			</li>
                <?php
    		}
    	}
    ?>
    </ul

    How can I check if the ID of the product we are on is in the array saved in the meta key os_linkto_product? and only show projects that are associated with the product we are on?

    I hope I have explained this correctly. I think I need to use meta_key, meta_value in my $args but not sure how.

    Thank you,

  • The topic ‘meta_value arrays’ is closed to new replies.