AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[wordpress](coding)

Martin Hope
Rodney Biddle
Asked: 2025-04-25 23:28:54 +0800 CST

我正在寻找如何使用 Shortcode 从 Wordpress 中当前活动页面提取帖子 ID 以应用于动态过滤器

  • 6

我在 Wordpress 中使用短代码,也用的是 Ninja Tables。代码是从 Google 电子表格中提取的,由一位非开发人员的管理员管理。操作起来很简单。我希望将其嵌入到模板中,而不是在所有帖子上手动安装短代码。

以下是我正在使用的短代码片段:

[ninja_tables id="446" search=0 filter="1100" filter_column="Filter4" columns="姓名,地址,城市,网站,Facebook"]

我正在寻找一种方法,让短代码可以使用变量代替筛选值“1100”,以便自动用当前帖子的帖子 ID 填充该值。这样就无需手动在帖子上输入短代码了。然后,我会手动将帖子 ID 添加到电子表格中,这样维护起来更容易。

我找到过一些关于 PHP 编程的参考资料,但我本身不是 PHP 开发者,也不想深入研究开发解决方案。希望能找到一个更简单的解决方案,包含一些变量,可以将页面详细信息读取到短代码中。

wordpress
  • 2 个回答
  • 36 Views
Martin Hope
timholz
Asked: 2025-04-16 20:05:13 +0800 CST

禁用 wp 6.8 中引入的推测加载

  • 8

WP 6.8 中是否有一个过滤器可以禁用推测加载?我试过:

apply_filters( 'wp_speculation_rules_configuration', null );

但脚本仍然存在。谢谢任何提示。

wordpress
  • 1 个回答
  • 46 Views
Martin Hope
Toniq
Asked: 2025-04-09 19:44:00 +0800 CST

MySQL SELECT WHERE IN 与另一个占位符混合

  • 2

此查询有效并返回预期结果:

$arr = [7,1];//dynamic
$vids = explode(',',$arr);
$in = implode(',', array_fill(0, count($ids), '%d'));

$stmt = $wpdb->prepare("
            SELECT mt.id, mt.title, mt.options, COUNT(DISTINCT ct.id) as comment_count, COUNT(DISTINCT lt.id) as like_count
            FROM $media_table as mt
            LEFT JOIN $comments_table ct ON ct.media_id = mt.id
            LEFT JOIN $like_table lt ON lt.media_id = mt.id
            WHERE mt.id IN ($in)
            GROUP BY mt.id 
            ORDER BY $sortOrder $sortDirection", $vids);

如果我print_r($stmt)得到:

     "SELECT mt.id, mt.title, mt.options, COUNT(DISTINCT ct.id) as comment_count, COUNT(DISTINCT lt.id) as like_count FROM wp_mvp_reel_media as mt LEFT JOIN wp_mvp_reel_comments ct ON ct.media_id = mt.id LEFT JOIN wp_mvp_reel_like lt ON lt.media_id = mt.id WHERE mt.id IN (7,1) GROUP BY mt.id ORDER BY order_id ASC"

当我添加MAX(lt.user_id = %d) AS user_liked)- 时查询失败。

如果我print_r($stmt),则返回一个空字符串"":

    $stmt = $wpdb->prepare("
                SELECT mt.id, mt.title, mt.options, COUNT(DISTINCT ct.id) as comment_count, COUNT(DISTINCT lt.id) as like_count, MAX(lt.user_id = %d) AS user_liked
                FROM $media_table as mt
                LEFT JOIN $comments_table ct ON ct.media_id = mt.id
                LEFT JOIN $like_table lt ON lt.media_id = mt.id
                WHERE mt.id IN ($in)
                GROUP BY mt.id 
                ORDER BY $sortOrder $sortDirection", $user_id, $vids);

wordpress
  • 1 个回答
  • 44 Views
Martin Hope
OverdueOrange
Asked: 2025-04-07 21:55:56 +0800 CST

如何在 WooCommerce 变量订阅产品上更改 x 个月的文本

  • 5

与此类似但不完全。

我有一个可变订阅产品,可以分 12 个月分期付款。

如果“分期付款次数”为“全额付款”,我希望能够更改 1 个月的 £xxx 文本:全额付款

然后将接下来的 11 期付款按 2 个月/3 个月等方式进行。

我知道此代码只会显示价格,但我似乎无法修改它以仅更改 1 个月(全额付款选项):

add_filter('woocommerce_subscriptions_product_price_string_inclusions', 'remove_subscription_inclusions', 10, 2);

function remove_subscription_inclusions( $include, $product ) {
    $include['subscription_length'] = '';
    $include['subscription_period'] = '';
    return $include;
}

我确实尝试过这个但没有任何效果:

add_filter('woocommerce_subscriptions_product_price_string_inclusions', 'custom_subscription_price_string_inclusions', 10, 2);

function custom_subscription_price_string_inclusions( $include, $product ) {
    // Check if the product is a subscription product
    if ($product->is_type('subscription')) {
        // Get the variations of the subscription product
        $variations = $product->get_available_variations();

        // Loop through each variation to check for the 1-month payment option
        foreach ($variations as $variation) {
            // Get the variation's price and subscription length/period
            $regular_price = $variation['display_price'];
            $subscription_length = isset($variation['attributes']['pa_subscription_length']) ? $variation['attributes']['pa_subscription_length'] : '';
            $subscription_period = isset($variation['attributes']['pa_subscription_period']) ? $variation['attributes']['pa_subscription_period'] : '';

            // Check if this variation is the 1 month (single payment) option
            if ('1' === $subscription_length && 'month' === $subscription_period) {
                // Modify the price string for the 1 month single payment option
                $include['price_string'] = '£' . $regular_price . ' (Full payment for 1 month)';
                // Remove subscription length and period to avoid duplication
                $include['subscription_length'] = '';
                $include['subscription_period'] = '';
            }
        }
    }

    return $include;
}

wordpress
  • 2 个回答
  • 69 Views
Martin Hope
HNNX
Asked: 2025-04-04 16:03:43 +0800 CST

如果与表单/下拉菜单交互后只有一个可用,Woocomerce 会自动选择产品变体

  • 5

我正在尝试为我的 woocommerce 产品找到一个解决方案,其中包含用户选择一个选项后的属性。

所有解决方案总是让我找到这个仅在页面加载时触发的代码片段 - 而不是在用户选择选项或与表单交互时触发。

add_filter('woocommerce_dropdown_variation_attribute_options_args','fun_select_default_option',10,1);
function fun_select_default_option( $args)
{
    if(count($args['options']) > 1) 
        $args['selected'] = $args['options'][0];
    return $args;
}

在我的例子中,我有一个产品,其属性为:功率 - 50W 和 100W

尺寸如果我选择 50W,则只剩下 100mm,并且应该自动选择如果我选择 100W,则只剩下 200mm,并且应该自动选择

音量如果我选择 50W,则只剩下 1 个变体,并且应该自动选择如果我选择 100W,则只剩下 1 个变体,并且应该自动选择

我尝试使用 javascript,但它在初始加载时就搞砸了。这似乎很奇怪,这不是 woocommerce 的现成选项。

是否有人曾经遇到过这个任务,或者知道我是否需要深入研究自定义 JS 而不是 PHP 钩子?

wordpress
  • 1 个回答
  • 20 Views
Martin Hope
Greg
Asked: 2025-03-05 22:50:47 +0800 CST

Google Tag Manager 正在破坏我用 Oxygen 构建的网站 (WordPress)

  • 5

在过去的一年里,我已经将 GTM 集成到我使用 Oxygen 构建的网站中,形式如下:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXX');
  gtag('config', 'GTM-XXXXX');
</script>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GT-XXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Google Analytics 和 AdWords 运行正常——我当时专注于最大化点击次数。大约 1.5 个月前,我将策略改为最大化转化,并在网站上创建了多个转化事件,而无需修改代码。一切都很顺利——我注意到用户参与度显著提高,预算利用率下降。但这种情况只持续了一段时间。

几天前,转换停止了。GTM 无法被调试器检测到,即使它在面板中显示为已连接。因此,我尝试将网站上的代码更改为 Google 建议的代码:

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXX');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

使用此版本,GTM 变得可见,并且在调试模式下测试时转换似乎可以正常工作。但是,出现了冲突,特别是与 Oxygen 插件有关 - 某些元素停止显示,甚至 Oxygen 编辑器也变得无法使用。此外,WP Maps Pro 插件处理的地图无法加载。

我尝试了所有方法——我分析了原始代码停止工作时所做的所有更改。我还修改了新代码,以防止它在 Oxygen 编辑器中加载,并确保它在所有其他脚本之后异步加载。然而,与地图的冲突仍然存在。我也不希望延迟加载对转换产生负面影响。

我也尝试通过各种插件添加 GTM,但每次从服务器加载 gtm.js 时,都会出现问题。

我还可以检查什么或者做什么?

//EDIT 根据要求从控制台添加屏幕截图。

控制台错误

wordpress
  • 1 个回答
  • 81 Views
Martin Hope
user3169905
Asked: 2025-02-14 10:37:21 +0800 CST

WordPress 用户登录后角色从“管理员”切换为“无”

  • 5

每当某些用户(但不是其他用户)登录 WordPress 网站时,他们的角色就会从“管理员”变为“无”。他们的名字、姓氏和昵称也会被设置为空白。对于不存在此问题的管理员,则必须登录、更新角色、重新添加名字、姓氏和昵称并保存。但下次受影响的用户登录时,它会恢复为“无”和空白字段。

我尝试禁用所有插件和主题,但问题仍然存在。WP Engine 支持也不确定发生了什么。这种情况不会发生在未托管在 WP Engine 上的单独暂存服务器上。

wordpress
  • 1 个回答
  • 19 Views
Martin Hope
BBLJ84
Asked: 2025-02-04 20:17:56 +0800 CST

是否可以防止灯箱控件和图像标题自动隐藏?

  • 5

下午好,

我正在尝试帮助一位朋友管理他们的网站,他们的一个愿望是只要灯箱图像处于打开状态,灯箱内的图像标题就保持可见。

默认情况下,图像标题和灯箱控件会在几秒钟后自动隐藏,如果鼠标移动,则会重新弹出。有没有办法防止这种情况发生,并且图像标题和控件仍然可见?

该网站使用 wordpress 构建,主题是 astra。我不确定 lightbox 是否已随主题预装,因为它未列在插件列表中

如果可能的话,我希望图像下方的标题始终保持可见并且不会自动隐藏。

感谢任何帮助,谢谢

wordpress
  • 1 个回答
  • 15 Views
Martin Hope
Marcin Budzy
Asked: 2025-01-20 00:49:06 +0800 CST

Twenty 24 Wordpess 主题中的子菜单隐藏在画廊下方(响应式灯箱和画廊)(Wordpress)

  • 5

我在(Wordpress)网站上遇到了问题:https://srv68534.seohost.com.pl/galerie/

单击“测试子菜单”时,子菜单位于图库下。但是,当我为子菜单添加更高的 z-index 时,我添加了额外的 css,然后子菜单标题在缩放(单击)图像上可见。

不知道这是插件还是子菜单的问题。我应该更改什么?

(Twenty 24 是子主题)插件:

我尝试:z-index:999999999!important; position:absolute;

用于子菜单元素。

我应该做哪些更改才能正确显示图库上的子菜单以及所有菜单标题上的放大(点击)图像?

wordpress
  • 1 个回答
  • 19 Views
Martin Hope
jstrother
Asked: 2025-01-02 07:59:43 +0800 CST

wp-scripts 未按预期加载 js 和 css

  • 5

我试图弄清楚为什么我的 WordPress 插件不再按预期加载我的 js 和 css。

在我的插件的主 php 文件中,我有以下代码(为简洁起见已编辑):

define('APV_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('BUILD_DIR', APV_PLUGIN_DIR . 'build/');

function __construct() {
    add_action('wp_enqueue_scripts', [$this, 'enqueue_styles'], 1, 0);
    add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 1, 0);
}

function enqueue_scripts() {
  wp_register_script('area-public-visualizer-script', BUILD_DIR . 'index.js');
  wp_enqueue_script('area-public-visualizer-script');
}

function enqueue_styles() {
  wp_register_style('area-public-visualizer-style', BUILD_DIR . 'index.css');
  wp_enqueue_style('area-public-visualizer-style');
}

但是,在我的浏览器控制台中,我得到了以下信息:

GET 错误

当我运行该wp-scripts start命令时,我的build/外观如下:

使用启动时构建目录

运行命令时wp-scripts build,它看起来像这样:

使用 build 时构建目录

以下是scripts我的部分package.json:

"scripts": {
    "build": "wp-scripts build src/index.js",
    "start": "wp-scripts start src/index.js"
}

我可以理解为什么我不能对我指定的文件进行GET-ing index.css,但我不知道为什么我不能GET-ing,index.js因为两个屏幕截图都很清楚。我更困惑的是,为什么几周前我的 css 和 js 都正常工作,但现在却不行了。

我在这里遗漏了什么?

编辑后添加:

我的 css 来自一系列 scss 文件,这些文件被收集到 中index.scss。然后,将此文件导入到src/index.js文件中。当之前这一切都正常工作时,我能够将index.css文件输出到构建目录中。

wordpress
  • 1 个回答
  • 22 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve