• Resolved marcorroma

    (@marcorroma)


    Hello.
    Is it possible to import a “sticky post” from an xml file?
    So that it is automatically set as “sticky post”.
    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @marcorroma

    Is it possible to import a “sticky post” from an xml file? So that it is automatically set as “sticky post”.

    You could use custom code and our pmxi_saved_post hook to do that: https://www.wpallimport.com/documentation/advanced/action-reference/#pmxi_saved_post.

    As an example, if you have an import element called {sticky[1]} with a value of “1” for sticky posts and a value of “0”, or anything else, for non-sticky posts, this snippet would work:

    function my_maybe_stick_imported_post( $id, $xml_data, $update ) {
    	$xml_record = json_decode( json_encode( (array) $xml_data ), 1 );
    	if ( array_key_exists( 'sticky', $xml_record ) ) {
    		if ( $xml_record['sticky'] == '1' ) {
    			stick_post( $id );
    		}
    	}
    }
    add_action( 'pmxi_saved_post', 'my_maybe_stick_imported_post', 10, 3 );
    Thread Starter marcorroma

    (@marcorroma)

    So, adding this code to my theme’s functions.php should it work?
    And in the xml file I set {sticky[1]} or {sticky[0]}. Correct?
    Thanks for support

    Plugin Author WP All Import

    (@wpallimport)

    Hey @marcorroma

    So, adding this code to my theme’s functions.php should it work?

    Yes.

    And in the xml file I set {sticky[1]} or {sticky[0]}. Correct?

    You should only have 1 sticky element per-record and it should either contain “0” or “1”. See:

    <sticky>1</sticky>

    Or:

    <sticky>0</sticky>

    Thread Starter marcorroma

    (@marcorroma)

    Thanks
    I will try it

    Plugin Author WP All Import

    (@wpallimport)

    Hi @marcorroma

    I’m marking this as resolved since we haven’t heard back. Let me know if you still have questions about this issue. Anyone else reading this, please start a new thread.

    Thread Starter marcorroma

    (@marcorroma)

    Good.
    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Import sticky post’ is closed to new replies.