Create additional short URL with custom field and 301 redirect

The first step is the rewrite rule. I’ve also added a rewrite tag so the custom query var will be parsed. You can also use the query_vars filter for this instead. add_action( ‘init’, ‘tipp_rewrite_rule’ ); function tipp_rewrite_rule() { add_rewrite_tag( ‘%trick_nummer%’, ‘([a-zA-Z0-9]+)’ ); add_rewrite_rule( ‘^tipp([a-zA-Z0-9]+)?’, ‘index.php?trick_nummer=$matches[1]’, ‘top’ ); } The second step is to intercept these … Read more

How to save values of a custom input field on the Network > Site Info screen

The problem was a redirect in site-info.php. After that the $_POST variable was empty in the code inserting in the admin_footer. I just need to use a further hook ‘admin_init’ and save the value here. add_action(‘admin_init’, ‘pg_save_custom_site_options’); function pg_save_custom_site_options(){ global $pagenow; if( ‘site-info.php’ == $pagenow && isset($_REQUEST[‘action’]) && ‘update-site’ == $_REQUEST[‘action’] ) { // Use … Read more

Match checkbox data with page title to show certain items

I managed to figure it out myself reading around, solved it with this: <div id=”grid”> <?php $args = array( ‘depth’ => 0, ‘child_of’ => 411 ); $pages = get_pages(array(‘child_of’)); $grid_title = $post->post_title; foreach($pages as $post) { setup_postdata($post); $fields = get_fields();?> <?php if($fields->company_name != “”) : ?> <!– Any new tags will need to be added … Read more

Adding a Nav menu to post admin

To see how such a list can be created look at the code in wp-admin/includes/nav-menu.php. Unfortunately, it is hard coded there, so you have to re-create the code. First, let’s create two menus: We can get these menus in PHP with wp_get_nav_menus() (a wrapper for get_terms()): $menus = wp_get_nav_menus(); print ‘<pre>’ . htmlspecialchars( print_r( $menus, … Read more

Adding existing user custom field value to a woocommerce product [closed]

You can do this with an action when a new product is inserted (and not when updated). As you did not specify the meta key this field is stored under the user as, OR the meta key of where you want it stored on the product: add_action( ‘wp_insert_post’, ‘smyles_insert_user_product_data’, 10, 3 ); function smyles_insert_user_product_data( $post_ID, … Read more

How to get a meta value from all post

get_col() function returns only one column as array. To get two column result we can use get_results(), Which will return an array of objects Which further can be converted into required structure using foreach loop. Example – function get_meta_values( $key = ”, $type=”post”, $status=”publish” ) { global $wpdb; if( empty( $key ) ) return; $r … Read more

Getting movie and serial on actor page

Hy, i resolve a problem, a liitle question, how can i get the text if nothing is selected in custom field ( distributie_serial). Ex: no serial for this actor. This is the Code that works. <?php $seriale = get_posts(array(‘post_type’ => ‘serial’, ‘meta_query’ => array( array(‘key’ => ‘distributie_serial’, // name of custom field ‘value’ => ‘”‘ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)