Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法让wordpress插件从xml文件填充选择选项。(自定义wordpress插件)_Php_Xml_Wordpress - Fatal编程技术网

Php 无法让wordpress插件从xml文件填充选择选项。(自定义wordpress插件)

Php 无法让wordpress插件从xml文件填充选择选项。(自定义wordpress插件),php,xml,wordpress,Php,Xml,Wordpress,嗨,谢谢你抽出时间。我一直在尝试为我正在进行的项目创建wordpress插件。它包含在汽车品牌/型号/年份的搜索表中。我遇到的问题是如何使用XML数据查询来填充make和model selects上的选项。这是我目前的代码: 编辑:我从XML中获取了数据,刚刚更新了代码,现在我缺少的是不起作用的条件参数。我在密码里标出了 <?php /* Plugin Name: Busqueda Rapida Plugin URI: Description: Plugin de busqueda ra

嗨,谢谢你抽出时间。我一直在尝试为我正在进行的项目创建wordpress插件。它包含在汽车品牌/型号/年份的搜索表中。我遇到的问题是如何使用XML数据查询来填充make和model selects上的选项。这是我目前的代码:

编辑:我从XML中获取了数据,刚刚更新了代码,现在我缺少的是不起作用的条件参数。我在密码里标出了

<?php
/*
Plugin Name: Busqueda Rapida
Plugin URI: 
Description: Plugin de busqueda rapida
Version: 1.0
Author: 
Author URI: 
*/


define( 'CD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'CD_PLUGIN_URL', plugin_dir_url( __FILE__ ) );


function html_form_code() {



$path =  CD_PLUGIN_PATH . 'marcamodelo.xml';
$doc = simplexml_load_file($path);


echo '<div class="buswrap"> ';
echo '<form id="buscaForm" method="POST" action="">';
echo '<fieldset>';
echo '<select id="marca" name="marca" class="select">';

foreach($doc->marca as $marca)
{
$selected = '';
if ($marca['name'] == **WHAT GOES HERE?** ) { // This is the conditional statement that doesn't work
    $selected =  ' selected ';
}

echo "<option value='".$marca['name']."' $selected>".$marca['name']."</option>";
}


echo '</select>';
echo '<select id="modelo" name="modelo" class="select">';

// Code to get model goes here

echo '</select>';
echo '<select id="year" name="year" class="select">';

for($i = 1950; $i < date("Y")+2; $i++){
  echo '<option value="'.$i.'">'.$i.'</option>';
}

echo '</select>';
echo '</fieldset>';
echo '<input type="submit" value="Buscar" id="search-bt" class="button">';
echo '</form>';

echo '</div>';
}

function generate_url() {


if(isset($_POST['marca'], $_POST['modelo'], $_POST['year'])) {
    // gather all the values
    $marca = urlencode($_POST['marca']);
    $modelo = urlencode($_POST['modelo']);
    $year = $_POST['year'];
    // make a header redirect
    header("Location: http://www.exampledomain.com/$marca/$modelo/$year");
    exit;
    }

}

function garaje_busqueda_rapida_shortcode() {
ob_start(); 
generate_url();
html_form_code();

return ob_get_clean();
}

add_shortcode( 'buscador-garaje', 'garaje_busqueda_rapida_shortcode' );

?>

我错过了什么?谁能给我指一下正确的方向吗?提前多谢

请不要在标题中添加编辑内容。默认的编辑历史记录已经足够让人们知道它已被编辑。哎呀!我的错。你能帮我查一下这个密码吗?