現在、社内使用する簡易的なシステムを構築する上でユーザー登録をしていないスタッフが管理画面を使用せずに削除ボタンを押したら記事が削除されるように実装したいのですが、うまくいっておりません。
システム自体にはベーシック認証をかけてありますので、今回はユーザー登録をあくまでもしない状態で記事の削除を行えないかご教授いただきたく質問をさせていただきました。
【現在のコード】
カスタム投稿の記事のタイトルをクリックで削除できるように実装したいと考えております。
PHP
1<ul> 2 <?php 3 $args02 = array( 4 'posts_per_page' => -1, 5 'post_type' => 'contact', 6 7 'tax_query' => array( 8 array( 9 'taxonomy' => 'select_shops', 10 'field' => 'slug', 11 'terms' => array( 'kashiwa02' ) 12 ), 13 ) 14 ); 15 ?> 16 17 <?php foreach ( get_posts( $args02 ) as $post ): setup_postdata($post); ?> 18 <li><a href="<?php echo get_delete_post_link( $post->ID ); ?>" onclick="return confirm('削除します。宜しいですか?')"><?php the_title(); ?></a></li> 19 <?php endforeach; ?> 20 </ul>
【変更後】
PHP
1 <ul> 2 <?php 3 $args02 = array( 4 'posts_per_page' => -1, 5 'post_type' => 'contact', 6 7 'tax_query' => array( 8 array( 9 'taxonomy' => 'select_shops', 10 'field' => 'slug', 11 'terms' => array( 'kashiwa02' ) 12 ), 13 ) 14 ); 15 ?> 16 17 <?php foreach ( get_posts( $args02 ) as $post): setup_postdata($post); ?> 18 <li><a href="<?php $post_id = the_ID(); wp_delete_post($post_id); ?>" onclick="return confirm('削除します。宜しいですか?')"><?php the_title(); ?></a></li> 19 <?php endforeach; ?> 20 21 </ul>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/09 16:50
2022/02/10 02:20