react – Programatically add “Web part gallery” in a custom web part in SharePoint Online

I have a custom web part that have different tabs. In two of the tabs/pivots I want the user to be able to add a web part from the web part gallery and to do so I need either to programatically add the web part gallery in my code, or add the specific out of the box web parts that needs to be shown (in this case the Stream web part and text web part). Is this possible?

How to attach images to current post being edited with acf custom field

I am using ACF, NOT the pro version, and I also have a plugin called ACF Photo Gallery Field that I am using to make user albums. I used CPT UI to make the custom post type “Albums” and added the gallery field with ACF. I am also using Elementor Pro to make my custom post template and ACF Frontend Form plugin to put the edit album/create album forms on the templates so users can create their own albums and add more images to them from the frontend. I use the Code Snippets plugin to add codes to my functions.php. I have also used the gallery widget through Elementor Pro and used the dynamic content to add post attachments to the gallery so the images will show up on my albums. Also, I have a “Create New Album” page with a form for making a new album. Everything for that works except the upload images field when I try to add images to the newly created album as it is being created. It all works if i do it from the backend, but not from the frontend. The problem I am having is that the images I have uploaded using my edit album form and the images added during the create new album process are not attaching to the current album/new album being edited/created. I have been searching for a solution for several weeks and nothing I have tried is working. I am very new at PHP and website development, but I know the basics of how the codes work. I just don’t know how to go about making something work the way I want it to. Here’s some of the codes I have tried… See examples below: (BTW, the custom field is named “album_images”)
My website address is (https://headsandhair.com)(1) – it is still in development, so only coming soon page shows right now.

ATTEMPT 1: I added this to functions.php because this example was given by the ACF Gallery plugin. I’m not exactly sure WHAT it does or where it was supposed to go, so I just added it to the Code Snippets plugin.

<?php
    //Get the images ids from the post_metadata
    $images = acf_photo_gallery('album_images', $post->ID);
    //Check if return array has anything in it
    if( count($images) ):
        //Cool, we got some data so now let's loop over it
        foreach($images as $image):
            $id = $image('id'); // The attachment id of the media
            $title = $image('title'); //The title
            $caption= $image('caption'); //The caption
            $full_image_url= $image('full_image_url'); //Full size image url
            $full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
            $thumbnail_image_url= $image('thumbnail_image_url'); //Get the thumbnail size image url 150px by 150px
            $url= $image('url'); //Goto any link when clicked
            $target= $image('target'); //Open normal or new tab
            $alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
            $class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
?>
<div class="col-xs-6 col-md-3">
    <div class="thumbnail">
        <?php if( !empty($url) ){ ?><a href="https://wordpress.org/plugins/navz-photo-gallery/<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
            <img src="https://wordpress.org/plugins/navz-photo-gallery/<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
        <?php if( !empty($url) ){ ?></a><?php } ?>
    </div>
</div>
<?php endforeach; endif; ?>

I also added this next snippet because it was also shown as an example on the gallery plugin…

acf_photo_gallery(album_images, POST_ID);

Then I tried this one because I saw it on this site somewhere…

function attachment_change_parent($aid,$pid) {
  $update_attachment_post = array(
    'ID'            => $aid,
    'post_parent'   => $pid
  );

  wp_update_post($update_attachment_post);
}

And I have tried several more things, but to no avail. I am just not sure how to do it and the ACF website has no information for it either. If anyone can help steer me in the right direction, that would be great! All I want to do is have the images uploaded with my custom field attach to the post that they are being submitted from or attach to the album being created. It sounds like it should just be easy, but obviously it’s not…Thanks!!!

List auhtor by his custom post count in current taxonomy

I have multi author website. I am trying to show author list ordered by his total post count. I use custom taxonomies and two (2) post types : “news” and “movies”. In the list author name, avatar and post count will displayed. and author url will be author post archive page . Please help me

<?php function get_authors_with($num = 5){
    global $wpdb;
    $term_slug = get_query_var( 'term' );
    $taxonomyName = get_query_var( 'taxonomy' );
    $current_term = get_queried_object( 'slug', $term_slug, $taxonomyName );
    $sub_q = $wpdb->prepare("SELECT * FROM $wpdb->posts
            INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
            INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
            WHERE ($wpdb->term_taxonomy.term_id = %s
            AND $wpdb->term_taxonomy.taxonomy = '%s'
            AND $wpdb->posts.post_type = 'news,movies'
            AND $wpdb->posts.post_status = 'publish')",
        $current_term->term_id,
        $taxonomyName
    );
    $sql = $wpdb->prepare("SELECT $wpdb->posts.post_author, FROM (%s)
            GROUP BY $wpdb->posts.post_author
            HAVING count(*) > %s",
            $sub_q,
            $num
    );
    return $wpdb->get_results($sql);
}
} ?>

python – Better way to define & load custom modules?

I have a project that would benefit from having a module folder where classes can be dropped in and automatically loaded.

Thus, I have:

.
├── main.py
└── modules
    ├── __init__.py
    ├── one.py
    ├── three.py
    └── two.py

my __init__.py looks like this:

__all__ = ('one', 'two', 'three')
from .one import test
from .two import test
from .three import test

And so the way I found to do what I want to do looks like this:

import modules 

for mod in modules.__all__: 
    getattr(modules, mod).test() 

Which is quite preferable to the other way I found to do this here, but I think my usage of __init__.py & __all__ may not be proper, and I’m thinking there must be a better/more pythonic way of doing this.

Furthermore, the from .x import y seems superfluous… and I also noticed that while this achieves what I want, it also pollutes modules‘s scope with the test method, which isn’t a huge deal since that will likely never be used, but that is partially why I’m thinking I’m doing something wrong, here.

Any advice and/or guidance is much appreciated.

php – How to add Text before my Custom Term and hide it when empty

This is my code:

    <?php
    $terms = get_the_terms( $post->ID , 'this_is_custom' );
    $links = ();
    foreach ( $terms as $term ) {
        $term_link = get_term_link( $term, 'this_is_custom' );
        if( !is_wp_error( $term_link ) ) {
            $links() = '<a href="' . $term_link . '">' . $term->name . '</a>';
        }
    }
    echo implode(',&nbsp;', $links);
    ?>

The result are:

Mango, Orange, Banana

What it wants to achieve is:

Tag: Mango, Orange, Banana

How can I display the word “Tag: ” and hide it when there is no Term inside current post?

Sorry for my English. I hope you understand.
Thanks for your answer, I really appreciated.

WooCommerce REST API: Filter orders by advanced custom field

I am using WooCommerce and Advanced Custom Fields for the orders.
Is there a way to filters orders using the WooCommerce REST API by a custom field?

I’m guessing if there is no built in solution, perhaps some custom function can allow this.

Thank you.

validation – showing yup validator custom error message

I’m trying to change yup error message

age must be a number type, but the final value was: NaN (cast from
the value "").

to something like this

please check this field

currently I’m using yup setLocale as the error message provider

export const yupLocale = {
mixed: {
    default: 'Não é válido',
    required: 'harus diisi'
},
number: {
    min: 'minimal ${min} karakter'
},
string: {
    email: 'email',
    min: ({ min }) => ({ key: 'minLength', options: { count: min } }),
    max: ({ max }) => ({ key: 'maxLength', options: { count: max } }),
}

};

where and what property should I add to my yuplocale object ?

url rewriting – 404 error- issues with pages after adding custom rules for posts

I am trying to create a custom translation for my website.

Quick Story:

I am facing “404 error-Page Not Found’ issues with pages after adding custom rules in functions.php

$newrules('^th/(.*)$') = 'index.php?name=$matches(1)';
$newrules('^se/(.*)$') = 'index.php?name=$matches(1)';

with the above code, posts with /th/ slug are working perfectly fine but my pages with /th/page-name-1 … throwing 404 error-Page Not Found

So here is the complete story:

First I created a parent page “Home Thai” https://mywebsite.com/th/
and under that parent page “Home Thai”, I added the rest of the Thai language pages, so results coming like this

mywebsite.com/th/page-name-1
mywebsite.com/th/page-name-2
mywebsite.com/th/page-name-3

Now I want to set up Thai Post URL with slug (/th), and to make this, I added the below new rules in functions.php

$newrules('^th/(.*)$') = 'index.php?name=$matches(1)';
$newrules('^se/(.*)$') = 'index.php?name=$matches(1)';

with the above code, posts are working perfectly with language slug (/th/, /se/). bit my pages with /th/page-name-1 … throwing 404 error-Page Not Found

Script:

//Create a function to register a new language translation taxonomy
add_action('init','nk_add_translation_taxonomy');

function nk_add_translation_taxonomy(){
   
    global $post;
    //set the name of the taxonomy
    $taxonomy = 'nk-post-translation';
    //set the types for the taxonomy
    $object_type = array('post');

    //populate our array of names for our taxonomy
    $labels = array(
        'name'               => 'Post Translation',
        'singular_name'      => 'Post Translation',
        'search_items'       => 'Search Translation',
        'all_items'          => 'All Translation',
        'parent_item'        => 'Parent Translation',
        'parent_item_colon'  => 'Parent Translation:',
        'update_item'        => 'Update Translation',
        'edit_item'          => 'Edit Translation',
        'add_new_item'       => 'Add New Translation', 
        'new_item_name'      => 'New Translation',
        'menu_name'          => 'Post Translation',
              
    );
    
    //define arguments to be used 
    $args = array(
        'labels'            => $labels,
        'hierarchical'      => true,
        'show_ui'           => true,
        'how_in_nav_menus'  => true,
        'public'            => false,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array('slug' => 'post-translation')
    );
    
    //call the register_taxonomy function
    register_taxonomy($taxonomy, $object_type, $args); 
}

add_filter( 'post_link', 'custom_permalink', 10, 3 ); 
add_filter( 'rewrite_rules_array','customLangaugeSlugRules');
add_filter( 'init','flushRules'); 

// creating of post permalink from taxnonmy slug
function custom_permalink( $permalink, $post, $leavename ) {
    $category = get_the_terms($post->ID,"nk-post-translation"); 

    if (  !empty($category) && $category(0)->slug == "th" )
    {
      $permalink = trailingslashit( home_url('th/' . $post->post_name ) );
    }
    elseif (  !empty($category) && $category(0)->slug == "se" )
    {
      $permalink = trailingslashit( home_url('se/' . $post->post_name ) );
    }
    else
    {
      $permalink = trailingslashit( home_url( $post->post_name ) ); 
    }
    return $permalink;
}

// using because of its flush the exixsting rules of taxnonmy slug rules
function flushRules(){
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
}

// inserting new rules of taxnonmy slug
function customLangaugeSlugRules($rules)
{
    $newrules = array();

    $newrules('^se/(.*)$') = 'index.php?name=$matches(1)';
    $newrules('^th/(.*)$') = 'index.php?name=$matches(1)';

    return $newrules + $rules;
}

How to fix the taxonomy and custom post type slug/url

I have a custom taxonomy and post type.

When I click on a taxonomy item the slug changes to:

http://localhost:8888/mysite/developments/development-name-here/

And that page is using taxonomy-developments.php

But when I click on an item there which is a custom post type item, the url changes to:

http://localhost:8888/mysite/our-properties/my-first-property/

This uses single-property.php

I would have though the url should be:

http://localhost:8888/mysite/developments/development-name-here/my-first-property

Because I want to show the property belonging to that development and thus have the url indicate that.

The post type:

register_post_type('property', array(
    'supports'      => array('title', 'editor', 'thumbnail', 'page-attributes'),
    'rewrite'       => array('slug' => 'our-properties'),
    'has_archive'   => true,
    'public'        => true,
    'show_in_rest'  => true,
    'hierarchical'  => true,
    'labels'        => array(
            'name'         => 'Property',
            'add_new_item' => 'Add New Property',
            'edit_item'    => 'Edit Property', 
            'all_items'    => 'All Properties',
    ),
));

Taxonomy:

register_taxonomy('developments',array('property'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'show_in_rest' => true,
    'rewrite' => array( 'slug' => 'developments' ),
));