Forum Replies Created

Viewing 11 replies - 16 through 26 (of 26 total)
  • Bump! Anybody have thoughts on this. I have a similar need. I have custom posts that are created/deleted through an external system and pulled into wordpress. Thus any user role (whether Subscriber or Admin) should not be able to delete or add a custom post type entry through the WP system. They will need to edit some info via WP.

    Thread Starter shagdirty

    (@shagdirty)

    I ended up figuring out a way to get this accomplished for those who may be curious. I’m not sure if this is the most efficient way to do it or not but it works…

    function makeMyMenus() {
    	$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
    	global $menuArray;
    	$menuArray = array('select a sub menu');
    
    	foreach ( $menus as $menu ) {
    		$menuArray[] = $menu->name;
    	}
    }
    makeMyMenus();
    
    // Adding sub menu drop down to pages.
    
    $meta_boxes[] = array(
    	'id' => 'sub_menu',
    	'title' => 'Sub Menu',
    	'pages' => array('page'), // applicable post types
    	'context' => 'side',
    	'priority' => 'low',
    	'fields' => array(
    		array(
    			'name' => 'Sub Menu',
    			'desc' => 'The sub menu for this page created via Appearance > Menus',
    			'id' => 'custom_menu',
    			'type' => 'select',
    			'options' => $menuArray
    		)
    	)
    );

    Use it on the front-end something like this…

    if( get_post_meta($post->ID, 'custom_menu', true) == true ) {
    $menuName = get_post_meta($post->ID, 'custom_menu', true);
    }
    
    wp_nav_menu( array('menu' => $menuName));
    Thread Starter shagdirty

    (@shagdirty)

    Actually I think I’ve found the solution via a search…

    if(empty($horse_var)){
       echo "horse_var is false";
    }else{
       echo "horse_var is true";
    }

    I’ll probably just wrap my whole query in this logic which should do the trick, albeit in a less than efficient fashion I’m sure.

    Rebuttal anyone?

    Thread Starter shagdirty

    (@shagdirty)

    WOOOOO! (in my Nature Boy Rick Flair voice). Worked like a charm! Thanks a million. Arrays become slightly less mystified to me.

    This raises another question, (perhaps for another post but since I have the attention of a savvy individual) If there’s nothing within post__in, query_posts returns everything I guess? that’s what my initial test shows me anyway. Is there a way around that off the top of your head? So if an array is empty will it return false so I can use some conditional logic or something?

    if $horse_var {
    // spit out the array in a different var maybe?
    } else {
    // nothing in the array so show a default post ID maybe???
    }

    Just so you know, $horse_var comes from here…

    $horse_var = get_the_author_meta( 'horses', $current_user->ID );

    So basically if the current user has horses associated with it, display those horses. If the current user has NO horses, I don’t want them to see ALL the horses. Clear as mud?

    thanks

    Thread Starter shagdirty

    (@shagdirty)

    Just tried using $horse_var in place of $horse_array but to no avail. If I do that, I get nothing back, not even the last item in the array. I get this when I dump horse_var:

    array(3) { [0]=> string(3) "546" [1]=> string(3) "540" [2]=> string(3) "550" }

    My logic (as ignorant and flawed as it may be) was to try and echo a string of post ID numbers. if I echo $horse_var I just get “Array” so I didn’t think that would work. I’m terrible with arrays so I’ve struggled pretty hard just to get to this point!

    Thread Starter shagdirty

    (@shagdirty)

    After a bit more Googling, I found this tutorial from Justin Tadlock about Adding and using custom user profile fields. Uses the hooks above but spells it out for coding-challenged folks like me.

    Thread Starter shagdirty

    (@shagdirty)

    excellent. thanks very much Rich. I’m sure that will get me started. More questions to come…

    Thread Starter shagdirty

    (@shagdirty)

    I was grossly overthinking this. I ended up creating a template and a page (so I had something to link to) that used that template and opening that url within shadowbox. All of the standard WP functions and loop work just fine, including the next/prev links. excellent

    Thread Starter shagdirty

    (@shagdirty)

    man, THANKS! that is exactly what I needed. worked like a charm.

    I know this is an old post but…

    @jim de Groot’s last code block is perfect for what I’m trying to do but I’d also like to display any posts by the filtered users as well. So, if a user has a specific custom role assigned, display his or her last X number of posts. I’ve done some digging but to no avail. I’m not great with php so any help would be appreciated.

    thanks, Shag

    I just had this issue however it was because I had renamed style.css. Must be css controlling something about that. possibly visibility? Didn’t do any more research into it.

Viewing 11 replies - 16 through 26 (of 26 total)