kazskater99
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: I saved metabox but not recored in my Phpadminwhat is the easy way to find price using sql inphpadmin this is problem i am facing php is great !
thank you
Forum: Fixing WordPress
In reply to: I saved metabox but not recored in my PhpadminThank you but still does not save meta key in my phpadmin not sure still workin on it.
Forum: Fixing WordPress
In reply to: I saved metabox but not recored in my Phpadminthank you for replaying i sent code i have now. not sure where i can save meta key to My phpadmin
Please help me!
Thank you
Forum: Fixing WordPress
In reply to: I saved metabox but not recored in my Phpadminfunction display_fields_table($post, $table_number) {
// custom_fields 配列を初期化
$custom_fields = array();
// テーブル番号によって表示するカスタムフィールドを設定
if ($table_number == 1) {
$custom_fields = array(
'Property_Name', 'Price', 'Units_Sold', 'Total_Units', 'Layout', 'Building_Area', 'Land_Area', 'Location', 'Transport',
'Ownership_Type', 'Land_Category', 'Zoning', 'Urban_Planning', 'Remarks',
'Image1', 'Image2', 'Image3', 'Image4', 'Image5', 'Image6',
'Image7', 'Image8', 'Image9', 'Image10',
);
} elseif ($table_number == 2) {
$custom_fields = array(
'NewProperty_Name', 'NewPrice', 'NewUnits_Sold', 'NewTotal_Units', 'NewLayout', 'NewBuilding_Area', 'NewLand_Area', 'NewLocation', 'NewTransport',
'NewOwnership_Type', 'NewLand_Category', 'NewZoning', 'NewUrban_Planning', 'NewRemarks',
'NewImage1', 'NewImage2', 'NewImage3', 'NewImage4', 'NewImage5', 'NewImage6',
'NewImage7', 'NewImage8', 'NewImage9', 'NewImage10',
);
} elseif ($table_number == 3) {
$custom_fields = array(
// 画像詳細関連のフィールド(AreaImageDetail)
'AreaDetail1', 'AreaDetail2', 'AreaDetail3', 'AreaDetail4',
'AreaDetail5', 'AreaDetail6', 'AreaDetail7', 'AreaDetail8',
'AreaDetail9', 'AreaDetail10', 'AreaDetail11', 'AreaDetail12',
'AreaDetail13', 'AreaDetail14', 'AreaDetail15', 'AreaDetail16',
'AreaDetail17', 'AreaDetail18', 'AreaDetail19', 'AreaDetail20',
// 画像関連のフィールド(AreaImage)
'AreaImageDetail1', 'AreaImageDetail2', 'AreaImageDetail3', 'AreaImageDetail4', 'AreaImageDetail5',
'AreaImageDetail6', 'AreaImageDetail7', 'AreaImageDetail8', 'AreaImageDetail9', 'AreaImageDetail10',
'AreaImageDetail11', 'AreaImageDetail12', 'AreaImageDetail13', 'AreaImageDetail14', 'AreaImageDetail15',
'AreaImageDetail16', 'AreaImageDetail17', 'AreaImageDetail18', 'AreaImageDetail19', 'AreaImageDetail20',
);
}
// フィールドをテーブル形式で出力
echo '<table class="form-table">';
// フィールドにカスタムフィールドをした名前を登録
foreach ($custom_fields as $field_name) {
$value = get_post_meta($post->ID, $field_name, true);
$link_value = get_post_meta($post->ID, $field_name . '_link', true); // ページのリンク先IDを取得
echo '<tr>';
echo '<th><label for="' . esc_attr($field_name) . '">' . esc_html($field_name) . '</label></th>'; // テキスト入力欄のカスタムフィールド
echo '<td>';
// 画像選択ボタンを追加
if (strpos($field_name, 'Image') !== false) {
// 画像選択ボタン
echo '<input type="text" name="' . esc_attr($field_name) . '" id="' . esc_attr($field_name) . '" value="' . esc_attr($value) . '" class="regular-text">';
echo '<input type="button" class="button button-secondary select-image" data-field="' . esc_attr($field_name) . '" value="Select Image">';
// 画像削除ボタン
echo '<input type="button" class="button button-secondary delete-image" data-field="' . esc_attr($field_name) . '" value="Delete Image">';
echo '<script>
jQuery(document).ready(function($) {
var mediaUploaders = {}; // 各画像用のメディアアップローダーを格納するオブジェクト
var formValues = {}; // フォームの入力値を一時的に保存するオブジェクト
// ページが読み込まれたときにフォームの値を保存する
$(".form-table").each(function() {
var formId = $(this).attr("id");
formValues[formId] = $(this).serializeArray();
});
// 画像選択ボタンがクリックされた時の処理
$(document).on("click", ".select-image", function(e) {
e.preventDefault();
var button = $(this);
var field = button.data("field");
console.log("Select image button clicked for field: " + field); // コンソールログを追加
// メディアアップローダーの作成または再利用
if (!mediaUploaders[field]) {
// メディアアップローダーがまだ存在しない場合は作成する
mediaUploaders[field] = wp.media.frames.file_frame = wp.media({
title: "画像を選択またはアップロード",
button: {
text: "この画像を使用"
},
multiple: false
});
// 画像が選択された時の処理
mediaUploaders[field].on("select", function() {
var attachment = mediaUploaders[field].state().get("selection").first().toJSON();
// 画像IDをフィールドに設定
$("#" + field).val(attachment.id);
// 画像プレビューを更新
$("#" + field + "_preview").html("<img src=\'" + attachment.url + "\' style=\'max-width:100%; height:auto;\'>");
// 画像を使用するボタンを有効化
button.siblings(".media-button-select").removeAttr("disabled");
// メディアアップローダーを閉じる
mediaUploaders[field].close();
// メディアモーダルの閉じるボタンをクリック
$(".media-modal-close").click();
});
}
// メディアアップローダーを開く
mediaUploaders[field].open();
});
// メディアアップローダーの閉じるボタンがクリックされた時の処理
$(document).on("click", ".media-modal-close", function() {
// メディアアップローダーを閉じる
var field = $(this).closest(".media-toolbar").siblings("input[type=\'hidden\']").attr("id");
if (mediaUploaders[field]) {
mediaUploaders[field].close();
// ボタンの disable 状態を解除
$(".media-button-select").removeAttr("disabled");
}
});
// メディアモーダルの外側(バックドロップ)がクリックされた時の処理
$(document).on("click", ".media-modal-backdrop", function() {
// メディアアップローダーを閉じる
var field = $(".media-toolbar-primary").siblings("input[type=\'hidden\']").attr("id");
if (mediaUploaders[field]) {
mediaUploaders[field].close();
// ボタンの disable 状態を解除
$(".media-button-select").removeAttr("disabled");
}
});
// 画像削除ボタンがクリックされた時の処理
$(document).on("click", ".delete-image", function(e) {
e.preventDefault();
var button = $(this);
var field = button.data("field");
// 画像IDを空にする
$("#" + field).val("");
// 画像プレビューを削除
$("#" + field + "_preview").html("");
// メディアアップローダーが存在する場合は閉じる
if (mediaUploaders[field]) {
// メディアアップローダーを閉じる
mediaUploaders[field].close();
// ボタンの disable 状態を解除
button.siblings(".media-button-select").removeAttr("disabled");
}
});
});
</script>';
// ページ選択セレクトボックス
echo '<select name="' . esc_attr($field_name) . '_link" id="' . esc_attr($field_name) . '_link">';
echo '<option value="">Select a page</option>';
$pages = get_pages(array('post_status' => 'publish')); // 公開中のページを取得
foreach ($pages as $page) {
$selected = ($link_value == $page->ID) ? 'selected' : ''; // 選択状態を設定
echo '<option value="' . esc_attr($page->ID) . '" ' . $selected . '>' . esc_html($page->post_title) . '</option>';
}
echo '</select>';
// 画像プレビュー
echo '<div id="' . esc_attr($field_name) . '_preview">';
if (!empty($value)) {
// 画像が設定されている場合
$image_url = wp_get_attachment_url($value); // 画像URLを取得
$page_url = get_permalink($link_value); // ページURLを取得
if (!empty($page_url)) {
// 画像がリンクされている場合
echo '<a href="' . esc_url($page_url) . '"><img src="' . esc_url($image_url) . '" style="max-width:100%; height:auto;"></a>';
} else {
// 画像だけが表示される場合
echo '<img src="' . esc_url($image_url) . '" style="max-width:100%; height:auto;">';
}
}
echo '</div>';
} else {
// 画像以外のフィールド
echo '<input type="text" name="' . esc_attr($field_name) . '" id="' . esc_attr($field_name) . '" value="' . esc_attr($value) . '" class="regular-text">';
}
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
// 画像とテキストのメタボックス
function add_custom_meta_boxes() {
global $custom_fields;
// $custom_fields が配列かどうかをチェック
if (is_array($custom_fields)) {
foreach ($custom_fields as $field_name) {
// 画像用のカスタムフィールド
if (strpos($field_name, 'Image') !== false) {
add_meta_box(
$field_name . '_metabox',
ucwords(str_replace('-', ' ', $field_name)) . ' Image',
'custom_image_meta_box_callback',
array('post', 'house'), // 'post' と 'house' 両方に対応
'normal',
'high',
array('field_name' => $field_name)
);
} else {
// テキスト用のカスタムフィールド
add_meta_box(
$field_name . '_metabox',
ucwords(str_replace('-', ' ', $field_name)) . ' Text',
'custom_field_meta_box_callback',
array('post', 'house'), // 'post' と 'house' 両方に対応
'normal',
'high',
array('field_name' => $field_name)
);
}
}
} else {
// $custom_fields が配列でない場合のエラーハンドリング
error_log('$custom_fields は配列ではありません。');
}
}
add_action('add_meta_boxes', 'add_custom_meta_boxes');
// caallback 関数は、WordPress の管理画面でメタボックスをレンダリングする役割を担います。この関数で HTML を出力することで、ユーザーがメタボックス内で情報を入力したり、選択したりできるようにします。
// 画像のメタボックスのコールバック関数
function custom_image_meta_box_callback($post, $metabox) {
// フィールド名とその値を取得
$field_name = $metabox['args']['field_name']; // 'New-Image1' など
$value = get_post_meta($post->ID, $field_name, true);
?>
<!-- ラベルと画像の表示 -->
<label for="<?php echo esc_attr($field_name); ?>"><?php echo $field_name; ?>:</label>
<?php if ($value): ?>
<img src="<?php echo esc_url($value); ?>" alt="<?php echo esc_attr($field_name); ?>" style="max-width: 100%; height: auto;">
<?php endif; ?>
<input type="file" name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="regular-text">
<?php
}
// テキスト入力の為のカスタムフィールドのメタボックスのコールバック関数
function custom_field_meta_box_callback($post, $metabox) {
// フィールド名を取得
$field_name = $metabox['args']['field_name'];
// 投稿のカスタムフィールドの値を取得
$value = get_post_meta($post->ID, $field_name, true);
?>
<!-- フィールドのラベルと入力フォーム -->
<label for="<?php echo esc_attr($field_name); ?>"><?php echo ucwords(str_replace('_', ' ', $field_name)); ?>:</label>
<input type="text" name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" value="<?php echo esc_attr($value); ?>" class="regular-text">
<?php
}
// $post_id: どの投稿に対してカスタムフィールドを追加または更新するかを示す ID。
// $field_name: meta_key に相当する、カスタムフィールドの名前(例: Property_Name)。
// $sanitized_value: そのフィールドに入力された値、これが meta_value になります。
function save_custom_fields_data($post_id) {
// 自動保存をスキップ
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// 投稿が新規作成の場合、またはWPが正しく処理している場合のみ
if (wp_is_post_revision($post_id)) return;
// 投稿タイプが'post' または 'house'の場合に処理
if (!isset($_POST['post_type']) || !in_array($_POST['post_type'], array('post', 'house'))) {
error_log("Not a valid post type or post_type is not set.");
return; // 投稿タイプが違う場合は処理をスキップ
}
// 投稿IDが正しいか確認
error_log("Post ID: " . $post_id);
// POSTデータの全フィールドをループして保存
foreach ($_POST as $field_name => $value) {
// カスタムフィールドであるかどうかの判定(プレフィックスチェックなし)
if (empty($field_name)) {
continue; // フィールド名が空であればスキップ
}
// 値をサニタイズ
if (is_array($value)) {
$sanitized_value = array_map('sanitize_text_field', $value);
} else {
$sanitized_value = sanitize_text_field($value);
}
error_log("Field: " . $field_name . " Value (Sanitized): " . print_r($sanitized_value, true));
// 画像アップロードの処理
if (isset($_FILES[$field_name]) && !empty($_FILES[$field_name]['tmp_name'])) {
$image_file = $_FILES[$field_name];
// 画像をアップロード
$uploaded_image = wp_handle_upload($image_file, array('test_form' => false));
if (isset($uploaded_image['url'])) {
// アップロードされた画像のURLを保存
$sanitized_value = $uploaded_image['url'];
} else {
// 画像アップロード失敗の場合
error_log("Image upload failed for field: " . $field_name);
$sanitized_value = ''; // エラーハンドリング
}
}
// カスタムフィールドを保存
update_post_meta($post_id, $field_name, $sanitized_value);
}
}
add_action('save_post', 'save_custom_fields_data');Forum: Fixing WordPress
In reply to: android view when wordpress broken??my android version 12 screen look different from pc or other mobile especially font and color
Forum: Fixing WordPress
In reply to: Insall WordPress as Manually Problemdoing this again not sure
Forum: Fixing WordPress
In reply to: Insall WordPress as Manually ProblemWordPressDatabase repair results
The?wp_users
?table is okay.
????
????Failed to optimize the?wp_users
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_usermeta
?table is okay.
????
????Failed to optimize the?wp_usermeta
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_posts
?table is okay.
????
????Failed to optimize the?wp_posts
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_comments
?table is okay.
????
????Failed to optimize the?wp_comments
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_links
?table is okay.
????
????Failed to optimize the?wp_links
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_options
?table is okay.
????
????Failed to optimize the?wp_options
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_postmeta
?table is okay.
????
????Failed to optimize the?wp_postmeta
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_terms
?table is okay.
????
????Failed to optimize the?wp_terms
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_term_taxonomy
?table is okay.
????
????Failed to optimize the?wp_term_taxonomy
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_term_relationships
?table is okay.
????
????Failed to optimize the?wp_term_relationships
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_termmeta
?table is okay.
????
????Failed to optimize the?wp_termmeta
?table. Error:?Table does not support optimize, doing recreate + analyze instead
The?wp_commentmeta
?table is okay.
????
????Failed to optimize the?wp_commentmeta
?table. Error:?Table does not support optimize, doing recreate + analyze instead
Repairs complete. Please remove the following line from wp-config.php to prevent this page from being used by unauthorized users.define('WP_ALLOW_REPAIR', true);
Forum: Fixing WordPress
In reply to: ACF Not shown up Field Nameok thank u
Forum: Fixing WordPress
In reply to: Table press problem error messgae show upok tanks!
Forum: Fixing WordPress
In reply to: admin-ajax.php 403 (Forbidden)yes thank you
Forum: Fixing WordPress
In reply to: admin-ajax.php 403 (Forbidden)still. POST https://gamewidth.net/wp-admin/admin-ajax.php 403 (Forbidden) not sure what to do .
Forum: Fixing WordPress
In reply to: admin-ajax.php 403 (Forbidden)remove this commnet i can use media library?
Forum: Fixing WordPress
In reply to: Creating Widget with html Not sure not stable…<?php // Weekly_Material_Schedule_Widget.php class Weekly_Material_Schedule_Widget extends WP_Widget { public function __construct() { parent::__construct( 'weekly-material-schedule', 'Weekly Material Schedule', array('description' => 'Display the weekly material farming schedule.') ); } public function widget($args, $instance) { echo '<div class="farming-schedule" id="farmingSchedule">'; echo $args['before_widget']; $title = !empty($instance['title']) ? $instance['title'] : ''; if ($title) { echo $args['before_title'] . apply_filters('widget_title', $title) . $args['after_title']; } $this->displayFarmingSchedule(); echo $args['after_widget']; echo '</div>'; } private function displayFarmingSchedule() { $today = date('l'); $characterMaterials = get_weekly_materials_data(); $weaponMaterials = get_weekly_weapon_materials_data(); $this->displayMaterialSection($characterMaterials, 'Character Ascension Materials', 'Covers Anemo, Geo, Electro, Dendro, Hydro, and Pyro characters.'); $this->displayMaterialSection($weaponMaterials, 'Weapon Ascension Materials', 'Covers Arrow, Catalyst, Claymore, Sword, Polearm basically.'); } private function displayMaterialSection($materials, $sectionTitle, $sectionDescription) { echo '<div class="farming-section">'; echo '<div class="farming-list">'; echo "<h2>$sectionTitle</h2>"; echo "<p>$sectionDescription</p>"; $todayMaterials = array_filter($materials, function ($material) use ($today) { $days = explode(', ', $material['days']); return isset($material['image']) && in_array($today, $days); }); if (!empty($todayMaterials)) { foreach ($todayMaterials as $material) { $this->displayMaterialItem($material); } } else { echo '<p>No data available for today.</p>'; } echo '</div>'; echo '</div>'; } private function displayMaterialItem($material) { echo '<div class="farming-list-item">'; echo '<div class="farming-icon-wrapper">'; echo '<img class="farming-icon" src="' . $material['image'] . '" alt="' . $material['name'] . '">'; echo '<p>' . $material['name'] . '</p>'; echo '</div>'; echo '</div>'; } public function update($new_instance, $old_instance) { $instance = array(); $instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; return $instance; } } ?> <!-- JavaScriptのコードを埋め込む --> <script> // ユーザーのローカルタイムゾーンに基づいて曜日、日付、時間を取得する関数 function getLocalDateTime() { const now = new Date(); const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short' }; return now.toLocaleString(undefined, options); } // ブラウザのローカルタイムゾーンで曜日、日付、時間を表示 function updateDateTime() { document.getElementById('farmingSchedule').innerHTML = ` <h2>Farmable Today</h2> <p>Today is ${getLocalDateTime()}</p> `; } // 1秒ごとに更新 setInterval(updateDateTime, 1000); </script>
Very Unstable WordPress Widget ….
cant not read html sometimes read html …
not sure
ok thank you
Forum: Fixing WordPress
In reply to: WARNING1 “media_video” block was affected by errorssomehow page is redirecong this when i submit https://www.ads-software.com/support/topic/warning1-media_video-block-was-affected-by-errors/page/2/#post-17420237