Delete or edit postmeta with specific meta_key?

Untested, but this might be what you’re looking for: $args = array( ‘fields’ => ‘ids’, ‘posts_per_page’ => -1, ‘post_type’ => ‘attachment’, ‘meta_key’ => ‘background-video’ ); $all_ids = new WP_Query( $args ); if ( $all_ids->have_posts() ) { while ( $all_ids->have_posts() ) { $all_ids->the_post(); update_post_meta( get_the_ID(), ‘background-video’, ” ); } } wp_reset_postdata(); References WP_Query » Usage » … Read more

I’m unable to call img path using single quotes in an array?

You’re trying to use PHP tags while inside a string: ‘<img src=”https://wordpress.stackexchange.com/questions/302344/<?php bloginfo(“template_directory’); ?>/images/social/facebook-share.png” />’ You need to instead use concatenation: ‘<img src=”‘ . esc_url( get_bloginfo(‘template_directory’) ) . ‘/images/social/facebook-share.png” />’ Or my personal favorite, sprintf(): sprintf( ‘<img src=”https://wordpress.stackexchange.com/questions/302344/%1$s/images/social/facebook-share.png” />’, esc_url( get_bloginfo(‘template_directory’) ) );

Add new post in existing categories using wp_insert_post

post_category is only for Core Categories. Use tax_input instead: $new_post = array( ‘post_title’ => esc_attr(strip_tags($title)), ‘post_content’ => esc_attr(strip_tags($description)), ‘post_type’ => ‘proiecte’, ‘post_status’ => ‘publish’, ‘tax_input’ => array( ‘categorie’ => array(17,16) ) ); $post_id = wp_insert_post($new_post); It may be clearer to other developers, and yourself in the future, if you use something other than categorie – … Read more

WordPress forms submissions and PHP files

Have you try with admin-post.php for your form submission. admin_post hook available in WordPress gives you great control over the flow of execution for your form. Using the above form, the following HTML content would execute the above hook when the user clicks either Submit. <form action=”http://www.example.com/wp-admin/admin-post.php” method=”post”> <input type=”hidden” name=”action” value=”custom_form”> <input type=”hidden” name=”data” … Read more

Need help with Code Correction php+wordpress

I see that you try to make some buttons with the links of the previous and the next publication, wordpress has many ways to get those links with functions, I will show you 4: // You are two functions print a tag with its respective link // Previous publication get_previous_post_link(); // Next post get_next_post_link(); With … Read more

Get the_content surrounded by instead of

First you should use get_the_content() to assign the content to a variable (instead of the_content() which is meant to display it instead of returning it). Then you will want to apply filters hooked to ‘the_content’ just like the_content() does (see the source). Here is a revised version of your original code: $thisPagesContent = get_the_content(); $thisPagesContent … Read more

Passing an array into WP_Query as a variable

First of all, you have a typo in your code. The variable with post IDs is called post_id_array, but your foreach loop uses post_ids_array (ids instead of id). When you fix this, then there’s one more problem. Meta query param should be an array of queries and each query should be an array. But your … Read more

How to display success message correctly and delete it when the page is refreshed

You’re looking for Flash Messages. Flash Messages are messages stored in session and deleted right after they are retrieved. You can find some implementation on github: https://github.com/plasticbrain/PhpFlashMessages <?php // Start a Session // Read about managing session with WordPress // Instantiate the class $fm = new \Plasticbrain\FlashMessages\FlashMessages(); // Process form e.g. send an email and … Read more