Forum Replies Created

Viewing 15 replies - 1 through 15 (of 52 total)
  • Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @threadi and @benjamin_zekavica. Your solution works like Magic. Thanks.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @benjamin_zekavica . How to use wp_nav_menu filter ? I am using like below.

    add_shortcode('country_name', 'country_name_shortcode');
    
    function country_name_shortcode($country_name) {
    
        return $country_name;
    
    }
    
    add_filter( 'wp_nav_menu', 'country_name_shortcode' );
    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @benjamin_zekavica .

    Sorry, I couldn’t express myself properly. I created a Shortcode named country_name and it is working perfectly in Posts.

    But I would like to use this shortcode with Menu like the screenshot. May be you are clear after check the screenshot.

    This Shortcode will show a Country name.

    How can I use the Shortcode with the menu like the screenshot ?

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @bcworkz. How to know which wp_nav_menu() is working ? I found lots of wp_nav_menu() in my current theme.

    What should I pass here $args->theme_location == 'primary' ?

    Thanks.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @nekokonez. I used

     [iplocator-code]

    But I am not getting any output.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @mqasimkh . But I can’t see Custom HTML in Menu. My menu is like below. May be I am doing mistake here .

    $args->theme_location == 'primary'
    enter image description here
    Thread Starter mabufoysal

    (@mabufoysal)

    @jayeshchopda, I used /wp-content/uploads/images/1712315199-6728.jpg this url.

    • This reply was modified 7 months, 3 weeks ago by mabufoysal.
    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @jayeshchopda. I used your code. But I can’t see Featured Image.

    enter image description here

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @t-p. I am creating post using wp_insert_post(). I would like to insert Post URL at that time. How can I do that ?

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @brickwork . But how can I catch $category in Server Side ?

    Could you please help me in this regard ?

    Thanks.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @thread. Here is the code to save post.

    public function save(): bool
    
    {
    
    global $wpdb; // Добавьте эту строку в начало функции, если она еще не добавлена
    
    // Проверяем, существует ли уже запись с таким же onlyfans_url.
    
    if ($this->onlyfans_url) {
    
    $existing_id = $wpdb->get_var($wpdb->prepare(
    
    "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'onlyfans_url' AND meta_value = %s LIMIT 1",
    
    $this->onlyfans_url
    
    ));
    
    // Если запись с таким URL уже существует, не создаем новый пост и возвращаем false.
    
    if ($existing_id) {
    
    return false;
    
    }
    
    }
    
    $success = false;
    
    if (0 === $this->id) {
    
    $args = array(
    
    'post_title' => $this->h1,
    
    'post_content' => $this->profile_text,
    
    'post_status' => 'publish',
    
    'post_type' => 'post',
    
    'meta_input' => $this->to_meta_array(),
    
    );
    
    $post_id = wp_insert_post($args);
    
    if (!is_wp_error($post_id)) {
    
    $this->id = $post_id;
    
    $success = true;
    
    }
    
    // Получаем ID категории 'United States'
    
    $united_states_term = term_exists('United States', 'category');
    
    if (!$united_states_term) {
    
    $united_states_term = wp_insert_term('United States', 'category');
    
    }
    
    $united_states_term_id = $united_states_term['term_id'] ?? null;
    
    // Убедитесь, что у нас есть действительный ID категории
    
    if ($united_states_term_id) {
    
    // Назначаем эту категорию посту
    
    wp_set_post_categories($this->id, [$united_states_term_id], true);
    
    }
    
    // Удаление категории 'Uncategorized', если она присвоена
    
    $uncategorized_term_id = get_option('default_category'); // ID категории 'Uncategorized' обычно установлено как категория по умолчанию в WordPress
    
    // Получаем существующие категории поста
    
    $current_categories = wp_get_post_categories($this->id);
    
    // Удаляем 'Uncategorized' из текущих категорий, если он там есть
    
    if (($key = array_search($uncategorized_term_id, $current_categories)) !== false) {
    
    unset($current_categories[$key]);
    
    }
    
    // Обновляем категории поста
    
    wp_set_post_categories($this->id, $current_categories);
    
    // added tags.
    
    if (0 !== $this->id) {
    
    // get country category.
    
    $country_term = get_term_by('slug', 'country', 'category');
    
    if ($country_term) {
    
    $country_term_id = $country_term->term_id;
    
    } else {
    
    $country_term = wp_insert_term('Country', 'category', array('slug' => 'country'));
    
    $country_term_id = $country_term['term_id'];
    
    }
    
    $tags = array();
    
    $categories = array();
    
    foreach ($this->tags as $tag) {
    
    // insert new term.
    
    if ($tag['is_country']) {
    
    // check exists tag.
    
    $term = get_term_by('slug', $tag['slug'], 'category');
    
    // add country category.
    
    $categories[] = $country_term_id;
    
    if ($term) {
    
    $categories[] = $term->term_id;
    
    continue;
    
    }
    
    $new_term = wp_insert_term(
    
    $tag['name'],
    
    'category',
    
    array(
    
    'slug' => $tag['slug'],
    
    'parent' => $country_term_id,
    
    )
    
    );
    
    if (!is_wp_error($new_term)) {
    
    $categories[] = $new_term['term_id'];
    
    }
    
    } else {
    
    // check exists tag.
    
    $term = get_term_by('slug', $tag['slug'], 'post_tag');
    
    if ($term) {
    
    $tags[] = $tag['slug'];
    
    continue;
    
    }
    
    $new_term = wp_insert_term($tag['name'], 'post_tag', array('slug' => $tag['slug']));
    
    if (!is_wp_error($new_term)) {
    
    $tags[] = $tag['slug'];
    
    }
    
    }
    
    }
    
    // unique value in array.
    
    $tags = array_unique($tags);
    
    $categories = array_unique($categories);
    
    if (!empty($tags)) {
    
    wp_set_post_tags($this->id, $tags, false);
    
    }
    
    if (!empty($categories)) {
    
    wp_set_post_categories($this->id, $categories, false);
    
    }
    
    }
    
    } else {
    
    $result = wp_update_post(
    
    array(
    
    'ID' => $this->id,
    
    'meta_input' => $this->to_meta_array(),
    
    )
    
    );
    
    if (!is_wp_error($result) && $result !== 0) {
    
    $success = true;
    
    }
    
    }
    
    return $success;
    
    }

    Is it possible to get ‘post_id’ in your below code ?

    add_action( 'wp_ajax_start_parsing', 'custom_function' );
    function custom_function() {
     var_dump($_POST['category_fans']);
    // ..
    }

    Thanks.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @thread. Yes, it is done via AJAX. Actually I need to save a Category when this code is saving a post. I added below code here.

    formData.append( 'category_fans', category_fans );

    Now I need to catch formData at Server Side.

    I couldn’t find ‘wp_ajax_start_parsing’.

    Could you please guide me in this regard ?

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @thread . Your explanation is nice. I searched your hook. But may beit is not available. Actually I would like to know how it is executed on the server side.

    I am looking for the root of the storing data. It is creating a post when it is storing data.

    Thanks a lot.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @threadi . If you check my Code you can find that I created API Key and News Infos . But I couldn’t create Add New. Could you please help me in this regard ?

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @threadi. I would like to show menu like below.

    API Key
    Add New
    News Infos

Viewing 15 replies - 1 through 15 (of 52 total)