daimaku
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Fixing WordPress
In reply to: adding post and postmeta using custom php file?i tried to follow your instructions, i have downloaded the page.php from my theme and i have added my custom code after the page code and before the end of the page, like this:
<?php /* Template Name: CustomPageT1 */ ?> <?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php // Start the loop. while ( have_posts() ) : the_post(); // Include the page content template. get_template_part( 'template-parts/content', 'page' ); // If comments are open or we have at least one comment, load up the comment template. if ( comments_open() || get_comments_number() ) { comments_template(); } // End of the loop. endwhile; ?> </main><!-- .site-main --> <?php get_sidebar( 'content-bottom' ); ?> </div><!-- .content-area --> <!-- custom code --> <?php $title_add="testing php post"; $content_add="<p align='justify'>just testing the add post using custom php</p>"; // Create post object $my_post = array( 'post_id' => 22, 'post_title' => $title_add, 'post_content' => $content_add, 'post_status' => 'publish', 'post_author' => 1, 'post_category' => array( 8,39 ) ); // Insert the post into the database wp_insert_post( $my_post ); add_post_meta(22,'_testing_post_meta_add','just text to let see if this is working'); function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { // Make sure meta is added to the post, not a revision. if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); } ?> <!-- end custom code --> <?php get_sidebar(); ?> <?php get_footer(); ?>
but it didn’t work, any help or tip will be very useful.
thanks in advance!
Viewing 1 replies (of 1 total)