• Hi there,

    I’ll get to my problem real quick: I want to display the childs of a certain parent as a list. In addition I want to filter these childs through their meta_value. Nothing special. But the meta_value of each post/page contains much shit because I am using ACF. However, I think I need to check the meta_values first, if they contain a certain string, then pass this to my actual array and get that list back.

    So I get into it more deeply:

    1. The custom fields
    'meta_key' => 'disciplines'
    This is what I want to filter first
    'meta_value' => 'concept'
    This is what the Plugin ACF wrote into my meta_value
    a:2:{i:0;s:7:"concept";i:1;s:6:"design";}

    So I want to check this table if it contains the word concept.

    2. The array
    Here I want to filter the posts, that are a child of the ID “8” and if they have the meta_value “concept” and give out an unordered list.

    <?php
    $concept = get_post_meta( $post->ID, 'concept', true );
    $pagestack = get_pages( array(
    	'child_of' => 8,
    	'sort_order' => 'asc',
    	'sort_column' => 'post_title',
    	'post_status' => 'publish',
    	'meta_value' => $concept
    ) );
    echo '<ul>';
    	foreach ($pagestack as $post){
    		echo '<li><a href="' . get_page_link($post->ID) . '" title="' . esc_attr( $post->post_title ) . '">';
    		echo get_the_post_thumbnail($post->ID, 'thumbnail', array('alt' => ''. esc_attr( $post->post_title ) .'', 'title' => ''. esc_attr( $post->post_title ) .'' ));
    		echo '<h2>' . esc_attr( $post->post_title ) . '</h2></a></li>';
    	}
    	//endforeach;
    echo '</ul>';
    ?>

    I hope this is understandable. Thank you very much for your help. I really appreciate it!

Viewing 5 replies - 1 through 5 (of 5 total)
  • $pagestack = get_pages(array( 'child_of' => 8, 'meta_value' => 'concept' ));
    It’s enough to get child pages with specified meta value.

    Thread Starter Sgt. Floyd Pepper

    (@sgt-floyd-pepper)

    Thanks for the quick reply. I have tried the simple way. But since my value is not exactly ‘concept’ it is not found.

    Just to make sure you understand my problem:

    Post #1 has the value:
    a:2:{i:0;s:7:"concept";i:1;s:6:"design";}

    Post #2 has the value:
    a:1:{i:0;s:6:"design";}

    Post #3 has the value:
    a:3:{i:0;s:7:"concept";i:1;s:6:"design";i:2;s:11:"development";}

    The values on posts #1 and #3 both contain the word ‘concept’. Now I want to have a post where just those two appear. I think I need to have some kind of query, which reads out all meta_values, compares them with the word ‘concept’ and then throws me the IDs.

    In addition I want to do this with the other two words ‘design’ and ‘development’ as well. I want to filter by content of the value, not the value itself.

    The values on posts #1 and #3 both contain the word ‘concept’. Now I want to have a post where just those two appear.

    $pagestack = get_pages(array( 'child_of' => 8, 'meta_value' => 'concept' ));
    it must work exactly this way.

    If you need to retrieve pages by multiple meta values, there is WP_Query and Custom Field Parameters.

    $args = array(
    	'post_type' => 'page',
    	'meta_query' => array(
    		array(
    			'key' => 'disciplines',
    			'value' => array('concept', 'design')
    		)
    	)
     );
    $the_query = new WP_Query( $args );

    Sgt. Floyd Pepper – forgive me, I spent a lot of time in front of screen today, there is my English also ) You need to check custom field and then query posts with same custom values, and when there is more than one values, it doesn’t want to work properly… Let me think about a solution )

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Array according to child_of and custom meta_value’ is closed to new replies.