Answer the question
In order to leave comments, you need to log in
How to pass value of selected checkbox to wordpress function array?
Hello! I'm trying to write the first plugin for wordpress (for myself). And here is the hitch with passing the variable to the array from the selected checkbox.
There is an array:
$posts = get_posts(array(
'post_type' => array('post','page')
));
<input type="checkbox" id="show_pages" value="page" /> Страницы
<input type="checkbox" id="show_posts" value="post" /> Записи
Answer the question
In order to leave comments, you need to log in
Settings API .
Well, or quite simply - checkboxes in the form, when submitting the form, do update_option( 'option_name' ). Then your output code will be like this:
$types = get_option( 'option_name' );
$posts = get_posts(array(
'post_type' => $types,
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question