$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - WP post meta - for loop inside for loop|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - WP post meta - for loop inside for loop

matteradmin10PV0评论

I wanna make a portfolio on-click opening images gallery using meta fields. So firstly I make array of portfolio images and loop them. Then I loop gallery images of every portfolio item, but it loops the same data, it's look like not saving properly. How to save properly so that every portfolio item will have own gallery images? Any help will be appreciated

Here my code:

for ($i = 0; $i < $portfolio_item_no; $i++ ){
    $html = "<img id='m_img_preview_m_img_$i' src='"  .$pi_main_img[$i] . "' alt='" . $pi_main_img_alt[$i] . "' />
    <input type='number' name='pi_slide_no[]' id='slideNo-$i' class='form-control' value='" . $pi_slide_no[$i] . "' />";

    for ($i2 = 0; $i2 < $pi_slide_no[$i]; $i2++ ){
        $html .= "<img id='slide_m_img_sld-$i-$i2' src='" . $pi_slide_img_link[$i2] . "' />
         <input type='hidden' id='slide_link_m_img_sld-$i-$i2' name='pi_slide_img_link[]' value='" . $pi_slide_img_link[$i2] . "' />";
    }
}

// To call
$pi_main_img = get_post_meta($post->ID, "_pim_main_img2", true);
$pi_main_img = ($pi_main_img != '') ? json_decode($pi_main_img) : array();
// ...

// To save
if ( isset( $_REQUEST['pi_main_img'] ) ) {
$pi_main_img = (isset($_POST['pi_main_img']) ? $_POST['pi_main_img'] : '');
$pi_main_img = strip_tags(json_encode($pi_main_img, JSON_UNESCAPED_UNICODE));
update_post_meta($post_id, "_pim_main_img2", $pi_main_img); 
}

if ( isset( $_REQUEST['pi_slide_img_link'] ) ) {
$pi_slide_img_link = (isset($_POST['pi_slide_img_link']) ? $_POST['pi_slide_img_link'] : '');
$pi_slide_img_link = strip_tags(json_encode($pi_slide_img_link, JSON_UNESCAPED_UNICODE));
update_post_meta($post_id, "_pim_slide_img_link2", $pi_slide_img_link); 
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far