• Resolved MACscr

    (@macscr)


    Is there a way to get the category ID with an export of posts (custom post type actually)? Seems I can get the category name, but I need the category ID as well.

    If I cant, I am assuming i could do a sql query field, but I dont see any docs on that and obviously would have to use the post id for that current row export in order to properly do a relevant sql query, so I would need to know what those variable names are, etc.

    • This topic was modified 4 years, 3 months ago by MACscr.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @macscr,

    Is there a way to get the category ID with an export of posts (custom post type actually)? Seems I can get the category name, but I need the category ID as well.

    You should use a custom PHP function on the “ID” export field to do that: https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/.

    Here’s an example function that you can modify as needed:

    function my_get_taxonomy_ids( $post_id ) {
    	$taxonomy = 'category';	
    	$categories = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'ids' ) );
    	if ( ! empty( $categories ) ) {
    		return implode( ',', $categories );
    	}
    }
    Thread Starter MACscr

    (@macscr)

    So of course a solution that only works with your pro version. =/

    Hello, I want only one category id here, How can i do that, its showing like this 45,96,76. But i want only the primary category.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘A posts category ID?’ is closed to new replies.