Skip to content

Instantly share code, notes, and snippets.

@walterjaworski
Created January 11, 2016 18:06
Show Gist options
  • Save walterjaworski/20f435b9e732d690f60e to your computer and use it in GitHub Desktop.
Save walterjaworski/20f435b9e732d690f60e to your computer and use it in GitHub Desktop.
Checkboxes com palestras e origem selecionada automaticamente
<fieldset>
<legend>Todas as palestras</legend>
<?php // WP_Query arguments
$args = array (
'post_type' => array( 'palestra' ),
);
// The Query
$palestras = new WP_Query( $args );
// The Loop
if ( $palestras->have_posts() ) {
while ( $palestras->have_posts() ) {
$palestras->the_post();
// Pega a url, extrai o array, extrai "id="" do array e retorna valor
$url = home_url( add_query_arg( NULL, NULL ) );
$tiraid = parse_url($url, PHP_URL_QUERY);
$resto = substr($tiraid, 3);
// Config Checked();
$checked = $resto;
$current = get_the_ID();
$echo = true;
echo '<br /><label><input type="checkbox" name="';
get_the_title();
echo '" value="';
get_the_ID();
echo '" ';
// Aqui a mágica acontece
if ( $checked == $current ) echo 'checked="checked"';
echo ' />';
the_title();
echo '</label><br />';
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
?>
<input type="submit" value="Enviar" /></fieldset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment