I have enabled Magento 2 Flat table, but how can I rebuild the table manually after add new product’s attributes
You need to run “reindex” command
php bin/magento indexer:reindex
I have enabled Magento 2 Flat table, but how can I rebuild the table manually after add new product’s attributes
You need to run “reindex” command
php bin/magento indexer:reindex
How can I remove an element of the array by a given value in PHP
You can use array_search to find the element by a given value and use unset to remove the element from the array.
if (($key = array_search($val, $array)) !== false) { unset($array[$key]); }
I would like to know if there is any way can create a Magento 2’s store programmatically.
You can call ‘StoreFactory’ class to create Magento 2’s website and use the store resource model to save the store object. Here is the example to create a Magento 2’s store programmatically
$storeFactory = \Magento\Framework\App\ObjectManager::getInstance() ->get('Magento\Store\Model\StoreFactory'); $storeResourceModel = \Magento\Framework\App\ObjectManager::getInstance() ->get('use Magento\Store\Model\ResourceModel\Store'); $websiteFactory = \Magento\Framework\App\ObjectManager::getInstance() ->get('Magento\Store\Model\WebsiteFactory'); $eventManager = \Magento\Framework\App\ObjectManager::getInstance() ->get('Magento\Framework\Event\ManagerInterface'); $website = $websiteFactory->create(); $website->load('your_website'); $groupid = 1; $store= $storeFactory->create(); $store->setCode('new_store'); $store->setName('New Store'); $store->setWebsite($website); $store->setGroupId($groupid); $store->setData('is_active','1'); $storeResourceModel->save($store); $eventManager->dispatch('store_add', ['store' => $store]);
How can I create Magento 2’s website programmatically, like from my custom Magento 2 extension
You can call ‘websiteFactory’ class to create Magento 2’s website and use the website resource model to save the website object. Here is the example to create a Magento 2’s website programmatically
$websiteFactory = \Magento\Framework\App\ObjectManager::getInstance() ->get('Magento\Store\Model\WebsiteFactory'); $websiteResourceModel = \Magento\Framework\App\ObjectManager::getInstance() ->get('use Magento\Store\Model\ResourceModel\Website'); $website = $websiteFactory->create(); $website->setCode('custom_code'); $website->setName('Custom Name'); $website->setDefaultGroupId(1); $websiteResourceModel->save($website);
I have created Magento 2 product programmatically, but how can I add or assign new products to exist Magento 2 categories
You will need to get Magento 2 product SKU and category ID first and call assignProductToCategories method from categoryLinkManagement class to assigning the products to exist Magento 2 categories
Here is the example
$sku = "test"; $cids = array(1,2,3); $link = \Magento\Framework\App\ObjectManager::getInstance() ->get('Magento\Catalog\Api\CategoryLinkManagementInterface'); $link->assignProductToCategories($sku,$cids);
I have a WordPress site and installed Yoast SEO plugin. I would like to know how can I update or insert Yoast SEO fields when I create a post or page programmatically
Yoast SEO is storing meta title and meta description via post meta. You can use get_post_meta function to retrieve the Yoast meta title or meta description fields and use add_post_meta or update_post_meta to insert or update the Yoast meta title or meta description
add_post_meta( 1, '_yoast_wpseo_metadesc', "Meta desc"); add_post_meta( 1, '_yoast_wpseo_title', "Meta title");
update_post_meta( 1, '_yoast_wpseo_metadesc', 'Meta desc' ); update_post_meta( 1, '_yoast_wpseo_title', 'Meta title' );
get_post_meta(1, '_yoast_wpseo_metadesc', true); get_post_meta(1, '_yoast_wpseo_title', true);
I would like to know how can I remove the attached function from a WordPress filter hook.
You can call WordPress function – remove_filter to remove the attached function if you know the hook name and attached funciton’s name
remove_filter( 'the_content', 'customfunction' );
I would like to print a list of all WordPress post type within my WordPress admin dashboard. So I can check it quickly when I am writing the plugin
You can use the get_post_types function to get a list of WordPress post type objects. Meanwhile, you can use “wp_add_dashboard_widget” to add your custom widgets for your WordPress admin dashboard.
function show_all_posttype() { $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; $post_types = get_post_types( $args, $output); echo '<ul>'; foreach ( $post_types as $post_type ) { echo '<li>' . $post_type . '</li>'; } echo '</ul>'; }
function posttype_dashboard() { if( current_user_can('manage_options') ) { wp_add_dashboard_widget( 'posttype_dashboard', 'WordPress Post Types', 'show_all_posttype' ); } } add_action( 'wp_dashboard_setup', 'posttype_dashboard' );
I have a Magento 2 store, I would like to setup a blog for my Magento 2 site. However does not want to use CMS like WordPress
You can search Magento 2 blog extension from Magento 2 marketplace like following
https://marketplace.magento.com/catalogsearch/result/?q=Blog
To install Magento 2 extension
- Via FTP client
- Connect to your server via FTP client
- Unzip the extension and upload into Magento 2 root directory
- Run the command to updates, compile and deploy the software
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy- Using Composer
- If your server support “Composer”, you can run the following command to install the Magento 2 extension
composer require vendorname/module-name php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy- Magento 2 Installation Service
If you have an issue with Magento 2 extension installation you can always request Service via Contact Us
After install Magento 2, I got error like Fatal error: Maximum function nesting level of ‘100’ reached, aborting!. How can I fix this Magento 2 error
If you have enabled the PHP extension – xdebug, you will get Fatal error: Maximum function nesting level of ‘100’ reached, aborting! .
xdebug.remote_autostart=0 xdebug.remote_enable=0 xdebug.profiler_enable=0
sudo php5dismod xdebug sudo service apache2 restart
For php7 (Ubuntu)
sudo phpdismod xdebug sudo service apache2 restart
xdebug.max_nesting_level = 200
ini_set('xdebug.max_nesting_level', 200);