associate image to WP page with PHP

0

I want to associate an image to a page / enter WP with the PHP function set_post_thumbnail ()

This is the code that I use:

require_once('wp-includes/post.php');
set_post_thumbnail( $_GET['page'],$_GET['img']);

where page and img are the received parameters (of a form, for example)

However, I get the following error that I do not know how to solve: Fatal error: Class 'WP_Post' not found in ... / wp-includes / post.php on line 546, can anyone help me fix it?

Can you associate the same image (a single ID) with different pages ???

In the WP administration panel it only lets you choose a page to which to associate the image but if I modify the table wp_posts (with SQL) and update the ID in the field post_parent (the page to which I associate the image) I keep the image in the previous ID (pages)

Thanks: D everyone, regards

    
asked by fede 13.03.2018 в 13:18
source

1 answer

0

The error message is clear:

  

Fatal error: Class 'WP_Post' not found in ... / wp-includes / post.php on   line 546

Apparently class WP_Post is not included or does not exist.

You should verify the following:

  • That in the file wp-setting.php (usually located in public_html ) you are including the class. There you have to find this line, without it being commented, of course:

    require( ABSPATH . WPINC . '/class-wp-post.php' );
    
  • Verify that there is a file in the public_html/wp-includes directory called class-wp-post.php

  • answered by 13.03.2018 в 14:03