Magento 2 WordPress Integration Post Types & Taxonomies Documentation

  • Installation

    You can install the module for Magento 2 using Composer or you can manually install it using FTP.

    Composer

    Run the following commands in your Magento 2 root directory to install the module using Composer.

    # Add the FishPig Composer repo
    composer config repositories.fishpig composer https://repo.fishpig.com/
    
    # Install the module using Composer
    composer require fishpig/magento2-wordpress-integration-cpt:*
    
    # Enable the module in Magento 2
    php bin/magento module:enable FishPig_WordPress_PostTypeTaxonomy
    
    # Run the Magento upgrade system
    php bin/magento setup:upgrade
    Manual

    You can download the latest version of the module by logging in to your account and selecting Account > Projects.

    Extract the ZIP file and upload the files to your Magento site at the directory below:

    When creating the folders, ensure you use the correct capitalisation.

    To complete the installation, run the following commands in a terminal.

    # Enable the module in Magento 2
    bin/magento module:enable FishPig_WordPress_PostTypeTaxonomy
    
    # Run the Magento upgrade system
    bin/magento setup:upgrade

    ↑ Back to Top

  • Testing

    Once the module is installed, you should be able to access your post type and taxonomy data in Magento.

    To do this, edit a post from a custom type in the WordPress Admin and click the View link. This should open the post in Magento. If this does not work, try flushing the Magento cache.

    You can also access custom post types in Magento at the code level. For more information on this, see the code examples page.

    ↑ Back to Top

  • Layout XML

    You can use Magento 2's layout XML feature to easily change templates for different post types and post type archive pages (the post type homepage).

    Post Type Homepage (Archive)

    Each custom post type can be configured to have it's own archive page. This is the homepage for the custom post type and lists all of the custom posts (just like /blog does for your default posts).

    To enable this page, ensure that when creating the post type, you set the has_archive option to True.

    To find the archive page, create or edit a post from your custom post type and then click the View Post link. If the archive page is enabled, you should see it in the breadcrumbs. If you don't see the breadcrumbs and you're using the Yoast SEO plugin, you may need to enable the Breadcrumbs feature.

    Change the Post Type Archive Page Template

    For this example, we will use the post type news_article. You will need to change this for your own post type.

    We will also assume that your custom theme lives at app/design/frontend/YourVendor/YourTheme.

    To target the post type archive page for the news_article post type, create the following file:

    
    
    
    
      
        
        
      
    
    

    Change the Post Type Archive Page Layout

    The page layout is the root template. For example, the root template may be 2columns-left (1 main column and 1 sidebar on the left). You can change this with the same file we used above.

    
    
    
      
        
      
    
    

    ↑ Back to Top