Advanced Custom Fields data from ancestor page - wordpress

I am trying to make ACF data available on child pages two levels under the parent. I have a solution for making it available to a child page:
if ( $post->post_parent ) {
$headingFont = get_field('community_heading_font', $post->post_parent);
$bodyFont = get_field('community_body_font', $post->post_parent);
$primaryColor = get_field('community_primary', $post->post_parent);
$secondaryColor = get_field('community_secondary', $post->post_parent);
$fifteenSecondaryColor = get_field('community_fifteen_secondary', $post->post_parent);
$tertiaryColor = get_field('community_tertiary', $post->post_parent);
}
However, this information isn't available once we're a level deeper. That is, the ACF field 'community_heading_font' isn't available to the grandchild of the page originally providing data for that field.
I've tried post->post_parent->post_parent, and I've also tried to use post->post_parent on a variable:
$parentPage = $post->post_parent;
$grandparentPage = $parentPage->post_parent

To get the $grandparentPage ID for use in your ACF functions, use the wp_get_post_parent_id() function.
$grandparentPage = wp_get_post_parent_id($post->post_parent);
$headingFont = get_field('community_heading_font', $grandparentPage);
https://codex.wordpress.org/Function_Reference/wp_get_post_parent_id

Related

How can I add a CSS Class to a Flask-Table Column

I want to add CSS Classes to specific Columns, the Table is made via Flask-Table. But I only found how to add Classes to the whole table is there a way to add classes to a Column too?
class Table(Table):
classes = ["table", "table-hover", "clickable-row", "sortable"]
username = Col("Username")
vorname = Col("Vorname")
nachname = Col("Nachname")
gebdat = DatetimeCol("Gebdat", datetime_format="dd.MM.yyyy")
admin = BoolCol("Rolle", yes_display='Admin', no_display='Benutzer')
aktiv = BoolCol("Status", yes_display='aktiviert',
no_display='deaktiviert')
edit = LinkCol("Bearbeiten", 'benutzerverwaltung.benutzerBearbeiten',
url_kwargs=dict(id='id'))
You can pass a dict in the column_html_attrs keyword argument when declaring a specific column inside the table class:
class MyTable(Table):
col = Col('Label', column_html_attrs = {'class': 'my-class'})
For more details check this example from the Flask-Table github.

Sylius - How to assign a Channel to a Product programmatically?

I am trying to assign a Channel to my products created programmatically, so they will be displayed on shop. Unfortunately, there is no documentation for this use case.
Here is how I create my products:
$productFactory = $this->container->get('sylius.factory.product');
$productManager = $this->container->get('sylius.manager.product');
$productRepository = $this->get('sylius.repository.product');
$productVariantFactory = $this->get('sylius.factory.product_variant');
$productVariantRepository = $this->get('sylius.repository.product_variant');
$channelPricingFactory = $this->get('sylius.factory.channel_pricing');
$channelPricingRepository = $this->get('sylius.repository.channel_pricing');
//CREATE PRODUCT
$product = $factory->createNew();
$product->setName('TEST 2 - '.$title);
$product->setCode($this->generateRandomString());
$product->setSlug($this->generateRandomString());
$productRepository->add($product);
//CREATE VARIANT & ATTACH IT TO PRODUCT
$variant = $productVariantFactory->createNew();
$variant->setName('TEST 2 - '.$title);
$variant->setCode($this->generateRandomString());
$variant->setProduct($product);
$productVariantRepository->add($variant);
//CREATE PRICE & ATTACH IT TO VARIANT
$channelPricing = $channelPricingFactory->createNew();
$channelPricing->setPrice(999);
$channelPricing->setOriginalPrice(999);
$channelPricing->setChannelCode('US_WEB');
$channelPricing->setProductVariant($variant);
$channelPricingRepository->add($channelPricing);
Unfortunately, the products are not linked to a Channel:
The answer to your question:
You have one product variant, but Product variant implements ProductVariantInterface which extends TranslatableInterface. So we need one translation to make it appear and work. To add the translation:
$productVariant->setCurrentLocale('fr_FR');
$productVariantTranslation = $productVariant->getTranslation();
or
$productVariantTranslation = $productVariant->getTranslation($locale);
after you can add a name or not:
$productVariantTranslation->setName('What a product variant!');
after:
$product->addVariant($productVariant);
$this->entityManager->persist($product);
You will have your product variant on line.
Another thing is that:
$channelPricingRepository = $this->get('sylius.repository.channel_pricing');
$channelPricingRepository->add($entity);
it's going to flush directly data to DB in each call. In the example you are going to flush 3 times instead only one. In bigger proccess with many "add" this can be a lack of performance. You can simply;
$this->entityManager->persist($entity); //Many times
$this->entityManager->flush();
Here is how I managed to create my products (to attach them then to my entities):
function createProduct($livre,$options){
$title = $livre['title'];
$prix = $livre['prix'];
// SYLIUS REPOSITORIES LOAD
$productFactory = $options['sylius_factory_product'];
$productRepository = $options['sylius_repository_product'];
$productVariantFactory = $options['sylius_factory_product_variant'];
$productVariantRepository = $options['sylius_repository_product_variant'];
$channelPricingFactory = $options['sylius_factory_channel_pricing'];
$channelPricingRepository = $options['sylius_repository_channel_pricing'];
//CREATE PRODUCT
$product = $productFactory->createNew();
$product->setName($title);
$product->setCode($title.'_'.$this->generateRandomString());
$product->setSlug($title.'_'.$this->generateRandomString());
$productRepository->add($product);
//CREATE VARIANT & ATTACH IT TO PRODUCT
$variant = $productVariantFactory->createNew();
$variant->setName($title. 'Variant');
$variant->setCode($title.'_'.$this->generateRandomString());
$variant->setProduct($product);
$productVariantRepository->add($variant);
//CREATE PRICE & ATTACH IT TO VARIANT
$channelPricing = $channelPricingFactory->createNew();
$channelPricing->setPrice($prix*100);
$channelPricing->setOriginalPrice($prix*100);
$channelPricing->setChannelCode('CH');
$channelPricing->setProductVariant($variant);
$channelPricingRepository->add($channelPricing);
$productId = $product->getId();
return $productId;
}
I added the channel to the product like this:
$channelCode = 'US_WEB'
$channelRepository = $this->get('sylius.repository.channel');
$channel = $channelRepository->findOneBy(array('code' => $channelCode));
$product->addChannel($channel);

wordpress: previous/next link needs to include certain categories only

I am currently using wordpress 3.6.
Since 3.3 the excluded_categories parameter is deprecated inside previous_post_link(), see http://codex.wordpress.org/Function_Reference/previous_post_link#Resources.
What is the recommended way to explicitly include or exclude categories now?
Use get_adjacent_post
$in_same_cat = false;/true
$excluded_categories = '';//cat
$previous = true;//false
$previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
$in_same_cat = false;//true
$excluded_categories = '';//cat
$previous = false;//true
$next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
get_adjacent_post

How to Advance filter for category and author in Smartsearch in kentico

I have created basic search and uses the SearchHelper to get smart search results based on the search paramaters.
Now creating the Advance search based on Category , Author etc but did not find the way to filter the result based on these condition.
I am looking for a way to display the results using the dataset that
// Prepare parameters
SearchParameters parameters = new SearchParameters()
{
SearchFor = searchText,
SearchSort = SearchHelper.GetSort(srt),
Path = path,
ClassNames = DocumentTypes,
CurrentCulture = culture,
DefaultCulture = defaultCulture,
CombineWithDefaultCulture = CombineWithDefaultCulture,
CheckPermissions = CheckPermissions,
SearchInAttachments = SearchInAttachments,
User = (UserInfo)CMSContext.CurrentUser,
SearchIndexes = Indexes,
StartingPosition = startPosition,
DisplayResults = displayResults,
NumberOfProcessedResults = numberOfProceeded,
NumberOfResults = 0,
AttachmentWhere = AttachmentsWhere,
AttachmentOrderBy = AttachmentsOrderBy,
BlockFieldOnlySearch = BlockFieldOnlySearch,
};
// Search
DataSet results = SearchHelper.Search(parameters);
The easiest way is to use the method:
SearchHelper.CombineSearchCondition()
The first parameter is the searchText, with the search terms you probably already have.
The second parameter is searchConditions, which can be formatted as per https://docs.kentico.com/k10/configuring-kentico/setting-up-search-on-your-website/smart-search-syntax
Alternatively you could just append your search conditions to your search text manually, separating each term with a space.
Remember that to filter based on any field they need to be selected as searchable in the SiteManager->Development->DocumentTypes->DocumentType->Search Tab.

How to insert term into vocabulary named Tag

I am trying to populate nodes by writing a script...i am using following code
$node->field_tags['und'][0]['textfield'] = 'first_tag';
$node->field_tags['und'][0]['textarea'] = 'This is tag';
$node->field_tags['und'][0]['tid'] = 2;
node_save($node);
whatsits doing is nothing and the term is not being added to vocabulary named tag...if i write the following code it will select the already existed term call xml..i guess because of tid=1;
$node->field_tags['und'][0]['textfield'] = 'first_tag';
$node->field_tags['und'][0]['textarea'] = 'This is tag';
$node->field_tags['und'][0]['tid'] = 2;
node_save($node);
i even tried the following code
$node->field_tags['und'][0]['name'] = 'first_tag';
$node->field_tags['und'][0]['description'] = 'This is tag';
$node->field_tags['und'][0]['tid'] = 2;
node_save($node);
can someone please help me how add terms into a already existed vocabulary
Get dynamically vid using below function
$vid = taxonomy_vocabulary_machine_name_load('vocabname');
$terms = new stdClass();
$terms->vid = $vid;
$terms->name='whatever name of your term';
taxonomy_term_save($terms);
Thanks,
Ankush
got it after reading hundreds of line code
$terms = new stdClass();
$terms->vid=1;
$terms->name='success';
$get_tid=new stdClass();
taxonomy_term_save($terms);
term will be save in vocabulary vid=1 with automatic tid....

Resources