• Zur Hauptnavigation springen
  • Skip to main content
  • Zur Hauptsidebar springen
  • Zur Fußzeile springen
Logo

CITROWEB Webdesign

Erste Wahl für Ihren Onlineauftritt

  • Home
  • Leistungen
    • Webdesign, Webentwicklung und Beratung
    • Online-Shops mit WooCommerce
    • Technische Unterstützung für WooCommerce-Shops
    • Suchmaschinenmarketing
      • SEO: Ihr Webauftritt erhält mehr relevante Besucher
      • SEA: Suchmaschinenwerbung für Ihren Webauftritt
    • Webhosting
  • Blog
  • Kontakt aufnehmen
Home » Blog » Set brand property (pa_brand) for all products

Set brand property (pa_brand) for all products

13. November 2021

We use the following code to programmatically set the pa_brand property for all products at once.


add_action('admin_init', 'iphf_add_brand_for_all_products');
function iphf_add_brand_for_all_products() {
	$queryArgs = array(
		 'post_type' => 'product',
		 'posts_per_page' => -1
	);

	$my_query = new WP_Query( $queryArgs );

	if( $my_query->have_posts() ) {

	   while ($my_query->have_posts()) : $my_query->the_post(); 

		 $term_taxonomy_ids = wp_set_object_terms( get_the_ID(), 'mein-marke', 'pa_brand', true );
		 $thedata = Array('pa_brand'=>Array(
		   'name'=>'pa_brand',
		   'value'=>'meine-marke',
		   'is_visible' => '1',
		   'is_taxonomy' => '1'
		 ));
		 update_post_meta( get_the_ID(),'_product_attributes', $thedata); 

	   endwhile;
	}

	wp_reset_query();
}

With is_visible comes a 1 (true), if brand should be displayed on the product page as „additional information“. If not desired, then insert 0. My-mark (bold in the code) must be replaced by the title form (slug) of the mark. The value for the title form can be found out in the editing mask of the property (Products -> Properties -> Configure terms click on Brand and then Edit on the corresponding brand).

Important remove this code after execution, so that the code is not executed every time the admin area is loaded and the loading is delayed.

Kategorie: WooCommerce

Haupt-Sidebar

  • How to remove dashicons in WordPress frontend?
  • How do I create a website (homepage) with ChatGPT?
  • Can I create a website (homepage) with ChatGPT?
  • iOS restrictions re: bringing up the keyboard on programmatic focus
  • iOS restrictions re: bringing up the keyboard on programmatic focus
  • Remove user listing from WP-JSON
  • Benutzerauflistung aus WP-JSON entfernen
  • What does „Video is not the main content of the page“ mean?
  • Was hat es mit „Das Video ist nicht der Hauptinhalt der Seite“ auf sich?
  • Remove WordPress logo from toolbar
  • Efficient onboarding simplified: LearnSuite – the cloud application for digital onboarding
  • Wir stellen vor: LearnSuite – Die Cloudanwendung für digitales Onboarding
  • Howto: How do I create a website (homepage) with ChatGPT?
  • Howto: Wie erstelle ich mit ChatGPT eine Website (Homepage)?
  • Can I create a website (homepage) with ChatGPT?
  • Kann ich mit ChatGPT eine Website (Homepage) erstellen?
  • Set noindex nofollow via .htaccess HTTP header
  • Über .htaccess X-Robots-Tag noindex nofollow setzen
  • How to remove WordPress Dashicons in frontend?
  • Wie lassen sich Dashicons im WordPress-Frontend entfernen?
  • DSGVO (3)
  • GDPR (3)
  • Genesis Framework (10)
  • Genesis-Framework (9)
  • Google Search Console (4)
  • Google Search Console (4)
  • Linux (3)
  • Linux (3)
  • mobile (3)
  • Mobile (3)
  • Network (1)
  • Netzwerk (1)
  • SEO (5)
  • SEO (5)
  • Trends (3)
  • Trends (4)
  • Uncategorized (3)
  • Web development (1)
  • Web hosting (1)
  • Webentwicklung (1)
  • Webhosting (1)
  • WooCommerce (9)
  • WooCommerce (9)
  • WordPress (23)
  • WordPress (24)

Footer

Logo




© 2026 CITROWEB
  • Datenschutz
  • Impressum