• On this page this part is still in italian. But the translations were working before.

    “L’appartamento si compone di: soggiorno con angolo cottura e divano letto doppio, 1 camera da letto tripla, 1 camera doppia, 1 bagno con doccia. 2 balconi, 1 posto auto”

    All the description is inserted by a shortcode but certains fields work and others dont

    The page I need help with: [log in to see the link]

Viewing 9 replies - 31 through 39 (of 39 total)
  • Moderator bcworkz

    (@bcworkz)

    Better, but yes, still some logical flaws. Do this:

    $lang = substr( get_locale(), 0, 2 );
    $terms = get_the_terms( get_the_ID(), 'intro');
    
    if ( is_array( $terms )) {
    	$term = $terms[0];		// get the zeroth element in array, a WP_Term object
    	if ( $lang == 'it' ){
    		$term_name = get_term_meta( $term->term_id , 'intro_'.$lang, true ) . ': ' ;
    	} else {
    		$term_name = $term->name . ': ' ;
    	} 
    } else {
       $term_name = '';
    }

    You’ll notice I removed the global $post; line. It did no harm, but is unnecessary. get_the_ID() is more reliable than global $post; $post->ID

    Thread Starter sacconi

    (@sacconi)

    Ok, it works! (You inverted the italian and the foreigner returns but inverting the data is fine). I did a little change for other taxonomies, I wonder if the last “else” redoubled is formally correct

    $lang = substr( get_locale(), 0, 2 );
    $terms = get_the_terms( get_the_ID(), 'soggiorno');
    
    if ( is_array( $terms )) {
        $term = $terms[0];        // get the zeroth element in array, a WP_Term object
        if ( $lang == 'it' ){$term_name2 = $term->name  ;
            $term_name2_str = empty( $term_name2 ) ? '' : "$term_name2, ";
    
        } else {$term_name2 = get_term_meta( $term->term_id , 'soggiorno_'.$lang, true )  ;
            $term_name2_str = empty( $term_name2 ) ? '' : "$term_name2, ";
        }
    } else {
       $term_name2 = '';
    $term_name2_str = '';
    }
    

    can I automatically print a tag in the tag box when I check one term of a taxonomy? It could be any term or some specific terms

    Moderator bcworkz

    (@bcworkz)

    Yes, you need the final else condition. It’s to account for when a post has no soggiorno terms assigned. If that should be the case and you don’t have this else condition, you’ll get an undefined variable error later on where $term_name2 or $term_name2_str is used to generate output. Even if you’re sure all posts will always have at least one term assigned, it’s best to be safe anyway.

    The empty() checks are to account for when no term meta value is available even though a term is assigned. No term assigned is a separate situation we need to account for with the final else condition.

    If you want a tag to appear the instant you check mark a taxonomy term, you need to do that with JavaScript or jQuery. Add a click event listener to all term check boxes. If any are checked, populate the tag field with an appropriate value.

    It’s probably easier to auto-assign a tag using PHP. The problem with this approach is the tag will not become visible until after the post is updated and the editor screen reloads.

    Thread Starter sacconi

    (@sacconi)

    Instead of creating a tag from a taxonomy term by JavaScript, I could simply create a check box in the search box connected to a custom taxonomy or to just specific terms of the taxonomy. So I will filter by tags + filter also by custom taxonomies throw check box and not throw a selector. Maybe I can continue in the other open topic, that is more ralated with a search query

    Moderator bcworkz

    (@bcworkz)

    It’s usually difficult to customize user interactions within the post editor unless it’s all done within a custom meta box or block. It’s relatively simple to assign or remove properties when the post is saved or updated, except the user doesn’t see the results until the editor page reloads.

    If you can achieve your goals by how the front end search form or the resulting search query works, all the better.

    If you think continuing in another topic makes more sense, that’s fine. But please drop a link to the continuing reply here in this topic. To get the link, after posting the reply, right-click its date stamp, then select “Copy link address”.

    Thread Starter sacconi

    (@sacconi)

    What is wrong in my last line? I’m trying to tell the code: “if the parking place doesnt exist (and no taxonomy term is checked)”, so write instead: “no parking place”. What I already did for a specific tag, but finallyI decided to use a taxonomy for the parking place

    $lang = substr( get_locale(), 0, 2 );
    $terms = get_the_terms( get_the_ID(), 'postoauto');
    
    if ( is_array( $terms )) {
        $term = $terms[0];        // get the zeroth element in array, a WP_Term object
        if ( $lang == 'it' ){$term_name8 = $term->name  ;
            $term_name8_str = empty( $term_name8 ) ? '' : "$term_name8. ";
    
        } else {$term_name8 = get_term_meta( $term->term_id , 'postoauto_'.$lang, true )  ;
            $term_name8_str = empty( $term_name8 ) ? '' : "$term_name8. ";
        }
    } else {
       $term_name8 = '';
    $term_name8_str = '__( "No parking place", "sacconicase" ) ';
    
    }
    

    I already tryed $term_name8_str = "__( 'No parking place, 'sacconicase' ) ";

    Moderator bcworkz

    (@bcworkz)

    Remove the quotes and concatenate the extra space: $term_name8_str = __( "No parking place", "sacconicase" ). ' ';

    Using double quotes like you also tried only works for variable values, not function calls. To use the double quote technique with gettext functions you’d need to do something like this:

    $trans = __( 'No parking place', 'sacconicase' );
    $term_name8_str = "$trans ";

    Your site’s content is not any of my business, but I question saying there is no parking when no term is assigned. Wouldn’t it be more accurate to say the parking situation is unknown? If you know there really is no parking available you ought to have a specific term for that. Do as you wish, but that’s my observation as a bystander.

    Thread Starter sacconi

    (@sacconi)

    It works! ..good…!

    I always have to know if there is one or more private parking spaces reserved for the customer or a shared parking space because this information is fundamental for customers. Often if there is no private parking space they don’t book. If there is no parking space, this information is now written automatically, which is more convenient for me. You were also wondering why I don’t create a specific term “without parking space”. Because in the future in the search box there will be a check-box to filter based on parking space, only one check box for all terms, and therefore if there was the term “without parking space”, I would also show the apartments without parking space

    Moderator bcworkz

    (@bcworkz)

    FWIW, a query for all terms can be set up to not include a no parking term. So it’d in fact be all terms except no parking. Similarly, no parking could be excluded from the checkbox list since no one would ever want that.

    If your schema works for you then that’s what you should do. Come to think of it, if I saw a listing with “parking unknown” I’d assume none is available, so my idea of a separate term doesn’t really accomplish much in actual practice.

Viewing 9 replies - 31 through 39 (of 39 total)

The topic ‘Problems with gettext in custom fields’ is closed to new replies.