Answer the question
In order to leave comments, you need to log in
Can I put php into a wordpress variable?
Hello. I'm stumped as I can't find any information on this topic. I would even be glad to answer "You can do this" or it's unrealistic.
There is a code, simple, that creates a post in WP based on the user's responses. Now you need to send responses to post_content that depend on the user's response when filling out the form (the form is sent by a POST request.
I created a test variable in which I want to place the code that includes php. The html tags are published, but there is a problem with inserting php.
$test = '
<? if(IsChecked('questions', $gkt)) { ?>
<h3 align="center" style="border: 2px solid #f9c6a9; padding: 10px; margin: 0 -2px 0 -2px; background-color: #f9c6a9;">Тут текст:
</h3>
<ul class="reddotsli">
<? if(IsChecked('questions','q1_a1')) {
echo ' <li>Первый ответ</li>';
}
?>
<? if(IsChecked('questions','q1_a2')) {
echo ' <li>Второй ответ';
}
?>
<? if(IsChecked('questions','q1_a3' || 'q1_a4')) {
echo ' <p><span class="reddot"></span>Третий ответ</p>';
}
?>
....................
';
$post_data = array(
'post_title' => 'Ответы',
'post_content' => $test,
'post_status' => 'private',
'post_author' => $user_ID,
'post_category' => [1],
'comment_status' => 'closed',
);
Answer the question
In order to leave comments, you need to log in
$post_content = '';
if ( IsChecked( 'questions', $gkt ) ) {
$post_content .= '<h3 class="title">Заголовок:</h3>';
$post_content .= '<ul class="list">';
}
if ( IsChecked( 'questions', 'q1_a1' ) ) {
$post_content .= '<li>Первый ответ</li>';
}
if ( IsChecked( 'questions', 'q1_a2' ) ) {
$post_content .= '<li>Второй ответ</li>';
}
if ( IsChecked( 'questions','q1_a3' ) || IsChecked( 'questions', 'q1_a4' ) ) {
$post_content .= '<li>Третий ответ</li>';
}
if ( IsChecked( 'questions', $gkt ) ) {
$post_content .= '</ul>';
}
IsChecked()
, but the data from the form comes to the $_POST variable , it needs to be checked is_checked()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question