wp insert post not working

This is not how variables work in PHP. You’re using them before they are defined. They’re not templates that will be replaced later. If you want to use those variables in $new_post then you need to define $new_post inside your loop after those variables are defined. function mic_create_new_page() { global $user_ID, $wpdb; $tableau_post = array … Read more

How to laod wp_enqueue_style to another header i created my self

WordPress features a very robust template hierarchy that should be observed, take a look at wphierarchy.com. If you needed two header formats for some reason, you could create a file in the theme root called header-manga.php which you could then call in your page template with <?php get_header( ‘manga’ ); ?>. Once you have your … Read more

selecting options from another form

In the following line: $select_branch = $wpdb->get_results($wpdb->prepare(“SELECT * FROM $table_name”));, you are using $wpdb->prepareincorrectly. wpdb::prepare needs two arguments, first one is a Query string with sprintf like placeholders and second an array of the values to to substitute the placeholders. More details here. And that is the error you are getting as posted on top … Read more

Weird query with get_posts and WP_Query

I just tried to replicate your code and the only issue I came up with is in one of the arguments to your CPT setup. You have “capability_type” => “comunicado”, But this prevented the CPT working correctly for me. I don’t think this argument should be referring to itself. I replaced it with ‘post’ to … Read more

Accessing WordPress Functions get_permalink() in Vanilla PHP?

The developer’s reference is a great place to start. You’ll find get_permalink in wp-includes/link-template.php. You might want to look into wp-cli wp post list –post__in=1 –field=url should do the trick as discussed in wp-cli issue#2727 Also, there’s the rest-api to consider. The best solution for getting the permalink might be to just post/cURL a request … Read more

Problem getting wp posts in plugin with wp_remote_get

I did some changes on my code $remoteargs = array( ‘timeout’ => 20, ‘redirection’ => 5, ‘httpversion’ => ‘1.1’, ‘blocking’ => false, ‘headers’ => array(), ‘cookies’ => array(), ‘body’ => array(), ‘sslverify’ => false, ); $response = wp_remote_get( ‘http://localhost/wordpress/wp-json/wp/v2/posts’,$remoteargs); // Exit if error. if ( is_wp_error( $response ) ) { echo $response->get_error_message(); return; } // … Read more

How to search pdf attachment?

I would recommend you first to search attachments by your search term. For example: $attachments_query = new WP_Query( array( ‘s’ => ‘Your search query’, // <– Your search term ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘application/pdf’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => -1, ) ); With this query, you will get all PDF files that fit your … Read more

How to save the Additional CSS in a CSS file and enqueue it

add_action(‘customize_register’, ‘theme_footer_customizer’); function theme_footer_customizer($wp_customize){ // Get upload directory $upload_dir = wp_get_upload_dir(); // Create style file path $style_file_path = sprintf( ‘%1$s/css’, untrailingslashit( $upload_dir[‘basedir’] ) ); // Create directories if they do not exist if( ! file_exists( $style_file_path ) ) { wp_mkdir_p( $style_file_path ); } // Sanitize contents ( probably needs to be sanitized better, maybe with … Read more