WordPress.org

Ready to get started?Download WordPress

Forums

Participants Database
[resolved] Checkbox results as links (5 posts)

  1. Sdarter
    Member
    Posted 1 year ago #

    This is coming together well for me, and I appreciate your responsiveness in the support forums!

    My database is of people who have completed certain courses, so one of the fields will be a checkbox field where we will select which courses the participant completed. So I have a list of Course A, Course B, Course C, etc., in the values field.

    What I would like is to be able to make those choices link to course descriptions. So in the output, if the participant completed Course A and Course C, they will list as links to a separate page.

    Can this be done? It seems simple in theory, but I'm not great at PHP. Trying to get better though!

    http://wordpress.org/extend/plugins/participants-database/

  2. xnau
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, it's possible, but a little tricky as the most direct way to do it is with string matching and replacing.

    The thing I'm not clear on is which shortcode are you using where you want the course names to be clickable? The single record?

    Anyway, the idea is you take the value (which is actually a series of values) break it up into it's parts, and then give each part its link. Tell me which shortcode it's for and I'll go into more detail.

  3. Sdarter
    Member
    Posted 1 year ago #

    The fields will show in the single record AND in the list. It is the "courses completed" field here:

    http://thestudentloanlawyer.com/workshop-graduates-2/

    and if you click through you'll see it on the single page as well.

  4. xnau
    Member
    Plugin Author

    Posted 1 year ago #

    Here's an example I created for my test site. This goes after the line that has $this->the_field() in it:

    <?php if ($this->field->name == 'interests') {
    	foreach ($this->field->value as &$string){
    		switch ($string) {
    			case 'fishing':
    				$link = 'fishing-page';
    				break;
    			case 'rock climbing':
    				$link = 'rock-climbing-page';
    				break;
    			default:
    				$link = false;
    		}
    		if ($link) $string = sprintf('<a href="%s">%s</a>',$link,$string);
    	}
    } ?>

    You just need to replace the string I used for my test case with the strings you'll have in your courses field. My field was named "interests" so you'll have to change that to the name of your courses checkbox field. This code will work in both templates.

    Note that this will only work for multi-select fields (like multiselect checkbox) that can have multiple values because such fields are stored as arrays.

  5. Sdarter
    Member
    Posted 1 year ago #

    AWESOME! Thank you so very very much.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic