Is_template how to add one more template [closed]

Here’s an example using the default WordPress is_page_template function: <?php if ( is_page_template( ‘base-gallery-rail.php’ ) ) { wp_enqueue_style(‘ztheme-gallery-style’); } else if ( is_page_template( ‘other-template.php’ ) ) { wp_enqueue_style(‘other-style’); } else { // the last else is only required if you want to have a default wp_enqueue_style(‘default’); } You can add as many else if ( … Read more

How to output a PHP file values by shortcode?

We’ve built shortcodes in the past using concatenating variables. To paraphrase the link above, you should output your PHP as such. $output=”<p>”; $output .= ‘<strong>’ . $content . ‘</strong>’; $output .= ‘</p>’; return $output; Note, see the .= variable concatenation.

Using WordPress gettext functions in a library outside plugin or theme scope

WordPress doesn’t quite have a practice of localizing something that isn’t core/plugin/theme. My educated guess would be that it will work just fine with same concepts, but you will have to write custom loading logic. Use lower level load_textdomain(), since higher level functions are meant for plugins/themes specifically. As long as you determine and load … Read more

Automatically add attributes to woocommerce product?

add_action( ‘save_post_product’, ‘create_product’, 10 ); function create_product( $post_id, $post) { // $post_id and $post are required if ( empty( $post_id ) || empty( $post ) ) { return; } // Dont’ save meta boxes for revisions or autosaves if ( defined( ‘DOING_AUTOSAVE’ ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) … Read more

Using fwrite() and “a” appends multiple times instead of once

You could try putting your code in a WordPress Action or Filter call: add_action( ‘init’, ‘my_file_function’ ); function my_file_function() { $content = “some text here\n”; $fp = fopen($_SERVER[‘DOCUMENT_ROOT’] . “/wp-content/themes/zerif-lite-child/myText.txt”,”a”); fwrite($fp,$content); fclose($fp); } The flag (‘a’ vs ‘wb’) doesn’t have anything to do with your problem, it just happens to showcase it. For whatever reason, … Read more

How to make a field appear only if a post meta field has a defined value?

I would store the meta value in a variable, and use an if/elseif statement to determine what should be displayed, like so: $registrazione_singolaono = get_post_meta( $post->ID, ‘registrazione_singolaono’, true ); $registrazione_multipla = get_post_meta( $post->ID, ‘registrazione_multipla’, true ); if ( ‘singolo_file’ == $registrazione_singolaono && ! empty( $registrazione_multipla ) ) { echo $registrazione_multipla; } elseif ( ‘piu_file’ == … Read more

I need to get an array from the wordpress database

Is this what you are asking for? Use it after the code you posted to create posts in loop and use thier ids to update meta fields. Replace “post_type” with your custom post type. foreach ($markers as $marker){ $post_id = wp_insert_post(array( “post_title” => “something”, “post_type” => “your-type”, “post_status” => “publish”, //by default they are drafts … Read more