• Resolved unuinplus

    (@unuinplus)


    How do I target the custom fields of the meta_value, where are the inputs for yasr_schema_title, yasr_recipe_cooktime, yasr_recipe_description, yasr_recipe_keywords, yasr_recipe_nutrition, yasr_recipe_preptime, yasr_recipe_recipecategory, yasr_recipe_recipecuisine, yasr_recipe_recipeingredient, yasr_recipe_recipeinstructions, yasr_recipe_video ?

    I am trying to target them to be filled up automatically when an article is created via a feed post with xpath comand, but for some reason they’re not filled up with the values extracted. But if I target the field yasr_schema_additional_fields it triggers as an error, so that tells me that that field is available for input in theory and is saw as a custom field, but the others aren’t filling up if I target them.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor dudo

    (@dudo)

    Hello, I’m not sure I understand the question, but as you have already guessed, the fields are just post meta grouped by the option name “yasr_schema_title” (for the title) and “yasr_schema_additional_fields” for all the other additional fields.

    In PHP, you can save that data by simply using the “update_post_meta” function. However, without seeing the code, it’s hard to say what is wrong.

    Best,
    Dario

    Thread Starter unuinplus

    (@unuinplus)

    the comand I am using for is for example: xpath|field_I_want_to_copy|yasr_recipe_cooktime

    Rule fomat is “extractionMethod|data|customFieldName”

    extractionMethod can be id,class,xpath or regex, and in my case is xpath or regex. The main idea is that when I specify the same thing to excerpt. example: regex|<meta name=”description” content=”(.*?)”|excerpt – would copy the description in the excerpt field.

    Thread Starter unuinplus

    (@unuinplus)

    Also, I have tried to use the following code, so I can post automatically in the fields of the fields, but without success:

    if (isset($_POST[‘yasr_schema_title’])) {
    update_post_meta($post_id, ‘yasr_schema_title’, sanitize_text_field($_POST[‘yasr_schema_title’]));
    }

    Thread Starter unuinplus

    (@unuinplus)

    SO I developed the folowing code in functions.php:

    function set_yarpp_meta_on_save_post( $post_id ) {
    // verific? dac? postarea este nou?
    if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
    return;
    }
    $yarpp_meta = array(
    ‘yarpp_display_for_this_post’ => ‘1’
    );

    update_post_meta( $post_id, 'yarpp_meta', serialize( $yarpp_meta ) );
    }
    add_action( ‘save_post’, ‘set_yarpp_meta_on_save_post’ );
    function save_yasr_schema_additional_fields( $post_id ) {
    $yasr_schema_additional_fields = array(
    ‘yasr_schema_title’ => get_the_title(),
    ‘yasr_recipe_description’ => get_the_excerpt(),
    ‘yasr_recipe_cooktime’ => ”,
    ‘yasr_recipe_keywords’ => ”,
    ‘yasr_recipe_nutrition’ => ”,
    ‘yasr_recipe_preptime’ => ”,
    ‘yasr_recipe_recipecategory’ => ”,
    ‘yasr_recipe_recipecuisine’ => ”,
    ‘yasr_recipe_recipeingredient’ => ”,
    ‘yasr_recipe_recipeinstructions’ => ”,
    ‘yasr_recipe_video’ => ”
    );
    foreach ( $yasr_schema_additional_fields as $field_name => $field_value ) { if ( ! empty( $_POST[ $field_name ] ) ) { $yasr_schema_additional_fields[ $field_name ] = sanitize_text_field( $_POST[ $field_name ] ); update_post_meta( $post_id, $field_name, $yasr_schema_additional_fields[ $field_name ] ); } } update_post_meta( $post_id, ‘yasr_schema_additional_fields’, serialize( $yasr_schema_additional_fields ) );
    }
    add_action( ‘save_post’, ‘save_yasr_schema_additional_fields’ );
    $yasr_schema_additional_fields = get_post_meta( get_the_ID(), ‘yasr_schema_additional_fields’, true );
    if ( $yasr_schema_additional_fields ) {
    $yasr_schema_additional_fields = unserialize( $yasr_schema_additional_fields );
    echo $yasr_schema_additional_fields[‘yasr_schema_title’]; echo $yasr_schema_additional_fields[‘yasr_recipe_cooktime’]; echo $yasr_schema_additional_fields[‘yasr_recipe_description’]; echo $yasr_schema_additional_fields[‘yasr_recipe_keywords’]; echo $yasr_schema_additional_fields[‘yasr_recipe_nutrition’]; echo $yasr_schema_additional_fields[‘yasr_recipe_preptime’]; echo $yasr_schema_additional_fields[‘yasr_recipe_recipecategory’]; echo $yasr_schema_additional_fields[‘yasr_recipe_recipecuisine’]; echo $yasr_schema_additional_fields[‘yasr_recipe_recipeingredient’]; echo $yasr_schema_additional_fields[‘yasr_recipe_recipeinstructions’]; echo $yasr_schema_additional_fields[‘yasr_recipe_video’];
    }

    And I get the following value in the SQL database:

    s:600:”a:11:{s:17:”yasr_schema_title”;s:37:”Demo name from post title”;s:23:”yasr_recipe_description”;s:141:”Demo description from excerpt”;s:20:”yasr_recipe_cooktime”;s:0:””;s:20:”yasr_recipe_keywords”;s:0:””;s:21:”yasr_recipe_nutrition”;s:0:””;s:20:”yasr_recipe_preptime”;s:0:””;s:26:”yasr_recipe_recipecategory”;s:0:””;s:25:”yasr_recipe_recipecuisine”;s:0:””;s:28:”yasr_recipe_recipeingredient”;s:0:””;s:30:”yasr_recipe_recipeinstructions”;s:0:””;s:17:”yasr_recipe_video”;s:0:””;}”;

    But the problem is that I get this error now in the article edit page:

    View post on imgur.com

    Plugin Contributor dudo

    (@dudo)

    The function save_yasr_schema_additional_fields is too complex, you don’t need all that code.

    Just use the one you find here https://pastebin.com/Wd7iEunF

    Also, there is no need to use the echo, once data is saved with the function above, it YASR will print it.

    Thread Starter unuinplus

    (@unuinplus)

    The code it works, but apparently I have an issue with the plugin itself, without having all the codes added.

    I use two domains, with the exaclty same files and everything, on domain1, the schema gets generated (without having any code alterations), but on domain2, it doesn’t show in the page code, and as well I didn’t alter the code. I have tried to delete and install the YASR, and also the wordpress itself, but the schema still doesn’t get generated.

    Thread Starter unuinplus

    (@unuinplus)

    I have made a backup, deleted everything, and left only with the YASR plugin. Still didn’t worked. I have tried older versions, and still the schema doesn’t show in the frontend code. Again, all these without touching with any code the plugin or the theme. It just gets frustrating af. I have tried other plugins with schema and works straight away in showing the schema.

    Thread Starter unuinplus

    (@unuinplus)

    After a lot of debug, I found some of the weird issues.

    1. Schema is not generated if “Enable stars next to the title?” is Disabled
    2. Schema is not generated only after someone votes the article
    3. Schema is not generated if ingredients fields are left empty

    Also, I have tried your code better, and it seems that if I complete some of the fields after it loads the values automatically, it wont save my new added values. Anyway.. in my case I need it more customized, as I am using it in combination with Automatic plugin. Thats why is also so important the custom_fields option to have it available, so I can target the text area fields to be filled automatically.

    Oh well.. so far the code I made it here https://pastebin.com/tEZGsxxk solves some of my needs.

    But please, try to address the issues above and fix them somehow, as the most annoying one is the 2nd one.

    As a side note/suggestion, try to make it to load by default the tags/keywords,name,categories and description, as it would make more sense, because those fields are already filled up most of the time when you create an article.

    • This reply was modified 1 year, 6 months ago by unuinplus.
    Plugin Contributor dudo

    (@dudo)

    A schema is generated if, and only if:

    • A YASR shortcode (yasr_visitor_votes or yasr_overall_rating) exists on the page. That’s why it returns if you enable it on the title.
    • There is at least one vote on one of these shortcodes.

    This is by design. YASR is a rating plugin, and the schema must only return if YASR is enabled for a certain post. Otherwise, YASR doesn’t return or load anything.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to target custom fields from meta_value’ is closed to new replies.