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 );
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
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>
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.