Hi
I’ve followed this tutorial series to achieve the dynamic population of a custom registration field:
and am working with this working base code:
add_action ("ws_plugin__s2member_before_custom_field_gen", "clubColors");
function clubColors ($vars = array())
{
$_field = &$vars["__refs"]["_field"];
if($_field["id"] === "club")
{
$_field["options"] = 'ABC|ABC' . "\n";
$_field["options"] .= 'HHYC|HHYC' . "\n";
$_field["options"] .= 'HKSF|HKSF' . "\n";
$_field["options"] .= 'HKSSA|HKSSA' . "\n";
$_field["options"] .= 'RHKYC|RHKYC';
}
}
What I am trying to achieve now is, instead of hard-coding the values as above, I want to populate the Club field with dynamically pulled data from a Custom Post Type query as follows:
<?php
$args = array (
'post_type' => array( 'regattaClub' ),
'post_status' => array( 'publish' )
);
// The Query
$clubs = new WP_Query( $args );
// The Loop
if ( $clubs->have_posts() ) {
while ( $clubs->have_posts() ) {
$clubs->the_post(); ?>
<?php the_title(); ?><br />
<?php }
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();?>
I’m unsure how to marry these two blocks of code together. This is sort of where I’m at, and it’s very obvious that I have no idea what I’m doing :
add_action ("ws_plugin__s2member_before_custom_field_gen", "clubColors");
function clubColors ($vars = array())
{
$_field = &$vars["__refs"]["_field"];
$hkoda = array (
'post_type' => array('regattaClub'),
'post_status' => array ('publish')
);
$clubs = new WP_Query ($hkoda);
$club = 'if ( $clubs->have_posts() ) {
while ( $clubs->have_posts() ) {
$clubs->the_post();
the_title();
}
}';
if($_field["id"] === "club")
{
$_field["options"] = $club . "\n";
}
}
Any help would be very much appreciated.