• Resolved estreet

    (@estreet)


    Hi all! I’ve been reading for quite a while now but this is my first time posting, I hope you guys can help I’m going crazy trying to figure this out.

    As some set up here is what I’m trying to do:

    A friend of mine runs a company newsletter using WordPress and I’m trying to use what I’ve been learning about WordPress plugins to help streamline his process.

    I’ve started the beginnings of a pretty basic plugin, and I just have one more hump I think I need to get over before I can really start moving with it.

    I have created a custom post type of ’employees.’ This is a list of all the current employees of the company, this is working fine.

    I also created a custom post type of ‘contributors_circle.’ This custom post type needs to be published every month. On the edit page is a list of all of the current post categories which loads fine, below each category and contributor can be selected from a dropdown of all the current employees.

    The category titles and employee dropdowns load correctly
    ( http://screencast.com/t/tDowMMkk3RM )

    I am saving the chosen employee for each Category as meta in the Contributors Circle custom post. The data saves correctly (which I’ve verified by printing the_meta() ), but it does not select the correct Employee name when the edit page loads. It should be selecting the employee that was saved as the contributor in the Contributors Circle Meta…

    I hope this all makes sense, I’ve pasted my code into paste bin, I’ve only pasted what is not working… the custom post setup, and meta saving is all working well, but I just can’t figure out which variable to pass to get the correct Employee name loaded when trying to add/update a Contributor’s Circle custom post.

    If I can provide any more information to help with solving this please let me know!! Looking forward to getting some help, this is frustrating I know I’m so close!

    Code:
    http://pastebin.com/d9zMCG3c

    Thank you for your time!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    If your problem is the if statement is always returning true, when you KNOW it shouldn’t, try using the ‘identical’ operator === instead of the usual == ‘equal’ comparison.

    A bit of a long shot. I don’t know why, it makes no sense. I’ve had this resolve similar issues related to comparing the value variable assigned when stepping through query results using foreach loops. Your $contributor_meta in the if statement contains data from $term, the foreach value variable, so your situation may be related.

    As I said, a long shot, but easy enough to try, even though it shouldn’t make a difference.

    Thread Starter estreet

    (@estreet)

    Gave it a shot, but no go. Maybe you can help me simplify this…

    I think I was over complicating it before so I’m trying to slim it down a bit. I wrote a separate function that takes one paramater which is a String of the name of the employee that should be selected from the list.

    The $select paramater is passing correctly, so I need to compare $select and the_title(), which is the title of the employee custom post (which is equal to the name).

    The conditional is not being run though even when the name of the employee (which is also the Employee Custom Post Type Title) equals the name I pass into the function.

    Depending on how I have things, either it will set $selected as ‘selected = “selected”‘ for all the names, or none of the names. I can’t for the life of me get it to only be set for the one name that matches string that I pass into the function.

    HELP!

    function display_employee_dropdown($select){
            echo 'Current Contributor is: ' . $select;     // Displays correctly as string
            $all_employees = new WP_Query('post_type=employees');
            ?>
            <select>
            <?php
            while($all_employees->have_posts()) : $all_employees->the_post();
                    // If the string passed into function equals the title of the custom employee post set $is_selected to select this option
                    if ($select == the_title()){
                            $is_selected = 'selected = "selected"';
                    } else {$is_selected = '';}
                    ?>
                    <option <?php echo $is_selected?> value="<?php echo the_title()?>"><?php echo the_title()?></option>
            <?php
            endwhile;
            ?>
            </select>
            <?php
    }
    Thread Starter estreet

    (@estreet)

    Well in case anyone else needs, I got the above function working using selected() instead of conditional statements. Very helpful as I plan on using dropdowns throughout several custom meta boxes.

    // Function used for displaying the employee dropdown
    // @param String $select = Employee name to be selected
    
    function display_employee_dropdown($select){
            $all_employees = new WP_Query('post_type=employees');
            ?>
            <select name="sitehook-contributor" id="sitehook-contributor">
            <?php $no_contributions = "No Contributions Received";?>
            <option <?php selected($select, $no_contributions)?> value="No Contributions Received">No Contributions Received</option>
            <?php
            while($all_employees->have_posts()) : $all_employees->the_post();
                    $the_employee_name = get_the_title(); ?>
                    <option <?php selected($select, $the_employee_name)?> value="<?php echo $the_employee_name?>"><?php echo $the_employee_name?></option>
            <?php
            endwhile;
            ?>
            </select>
            <?php
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cant Figure Out How to Reset the Loop…’ is closed to new replies.