WordPress.org

Ready to get started?Download WordPress

Forums

Call custom post page based on meta value (1 post)

  1. obidos
    Member
    Posted 1 year ago #

    Hi everyone,

    I have done a lot of searching and a lot of attempts but having some trouble getting this to work.

    I have a custom post type called price. In here I have a custom meta box that lists all the pages within my website along with a checkbox. What happens is admin creates a price and then assigns it to multiple pages by ticking the checkbox.

    So what I have in the database in wp_postmeta is a meta_key called 'ap_linkto_page' and a list of page ids e.g. '7,86,16,12'.

    Now for each page on the the front-end I need to list the prices but only the prices that are assigned to the page we are on. So the above price is attached to page id 7,86,16,12 so if I am on any of those pages I need to show the price.

    Any ideas how I can get this to work? This is all I have but it just lists all prices.

    if (count($arr) > 0)
    {
    	$i = 1;
    	$args = array(
    		'post_type'		 => 'price',
    		'posts_per_page'	=> -1,
    		'orderby'		   => 'menu_order'
            );
            $prices = get_posts($args);
    	foreach($prices as $price)
            {
    		echo $price->post_title;
    	}
    }

    I think I need to explode the array of ids and add the id in to the args somehow. Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic