-
-
Save leobaiano/9cba3ebe58309aabf1af to your computer and use it in GitHub Desktop.
Checkboxes com palestras e origem selecionada automaticamente
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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