• tomazpipan

    (@tomazpipan)


    Hi all!

    I will cut to thre chase:

    I define custom fields in each Page that I publish and I would like the wp_list_pages() to sort the list in the side bar by a given custom field. Is that possible?

    For example: I have a key called Project. I can have 3 values for that (A, B and C). Can I tell to list the pages in the wp_list_pages() tag according to these values? If not is there any other way instead of using wp_list_pages tag?

    It would be great if someone can help me out I am really getting desperate on this one!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tomazpipan

    (@tomazpipan)

    OK, I have came this far.

    I made a function called proba() that lists all the page IDs classified by meta values and those clasified by meta keys. I just don’t know how to make this IDs into LINKS to the real pages that correspond to the IDs!

    here is the code

    <?php
    //my stuff

    function proba() {
    global $wpdb;
    $proba_metakeys = $wpdb->get_results(“SELECT meta_key FROM $wpdb->posts, $wpdb->postmeta GROUP BY ‘meta_key'”);

    foreach ($proba_metakeys as $proba_metakey)
    {
    echo $proba_metakey->meta_key;
    echo “<br>”;
    $proba_metavalues = $wpdb->get_results(“SELECT meta_value FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = ‘$proba_metakey->meta_key’ GROUP BY ‘meta_value'”);
    foreach ($proba_metavalues as $proba_metavalue)
    {
    echo “<p> $proba_metavalue->meta_value </p>”;
    $proba_metaids = $wpdb->get_results(“SELECT post_id FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = ‘$proba_metakey->meta_key’ AND meta_value = ‘$proba_metavalue->meta_value’ GROUP BY ‘post_id'”);
    foreach ($proba_metaids as $proba_metaid)
    {
    echo “<h4> $proba_metaid->post_id </h4>”;
    }
    }
    }
    }
    ?>

    If someone can help me on this; it would be great!!

    Thread Starter tomazpipan

    (@tomazpipan)

    Nearly there: this is it; the function incorporates the wp_list_pages() function to list the sorted page IDs. Now All I need is to show only one meta_tag list at the time, preferably selected from a drop down menu (wich menas that the first query is unnecessery – object &proba_metakey would get replaced by a selected object from the drop down button)

    <?php
    function proba()
    {
    global $wpdb;
    $proba_metakeys = $wpdb->get_results("SELECT meta_key FROM $wpdb->posts, $wpdb->postmeta GROUP BY 'meta_key'");
    
    foreach ($proba_metakeys as $proba_metakey)
    	{
    	echo $proba_metakey->meta_key;
    	echo "<br>";
    	$proba_metavalues = $wpdb->get_results("SELECT meta_value FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = '$proba_metakey->meta_key' GROUP BY 'meta_value'");
    	foreach ($proba_metavalues as $proba_metavalue)
    		{
    		echo " $proba_metavalue->meta_value";
    		$proba_metaids = $wpdb->get_results("SELECT post_id FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = '$proba_metakey->meta_key' AND meta_value = '$proba_metavalue->meta_value' GROUP BY 'post_id'");
    		foreach ($proba_metaids as $proba_metaid)
    			{
    			echo "<h4> $proba_metaid->post_id </h4>";
    			echo wp_list_pages("include=".$proba_metaid->post_id);
    			}
    		}
    	}
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List pages by meta tag’ is closed to new replies.